Back to Browse

Window FRAMES in SQL | Difference in ROWS and RANGE | SQL Intermediate Level Interview Question

4.3K views
Aug 4, 2024
5:10

Namastey All, Welcome to Select Star. Today I am solving a medium level interview question. We have been provided a table (balance) and we required to find the final amount after each transaction. Topics covered : 1. Window Function SUM, PARTITION BY and ORDER BY 2. Window Frames : Default FRAME for a SUM window function is range between unbounded preceding and current row. 3. Running SUM (SUM with OVER clause) 4. Difference between RANGE and ROWS : Range considers whatever you mention in ORDER BY clause as one frame however ROWS considers the physical position of rows as frame. 5. CASE statement inside SUM Related Playlists: 1. Basic SQL Course : https://www.youtube.com/playlist?list=PLNSZGqZkgdshcIgg8bioPpZmoB6gZoXmW 2. SQL Easy Interview Questions : https://www.youtube.com/playlist?list=PLNSZGqZkgdsgmzuSYSl7WDdrfMk_AvsrR 3. SQL Mediun to Hard Level Interview Questions : https://www.youtube.com/playlist?list=PLNSZGqZkgdsjdUQTAJ8VTCtngY_XNE-1a If you want me to solve some specific questions, then email me : [email protected] Script for table creation : create table balance ( customer char(1), transaction_type varchar(10), transaction_date date, amount int); insert into balance values ('A','Credit','2024-01-01',10000), ('A','Credit','2024-03-01',5000), ('A','Debit','2024-03-05',2000), ('B','Credit','2024-02-01',1000), ('B','Credit','2024-02-01',2000), ('B','Debit','2024-02-03',4000), ('C','Credit','2024-01-15',5000), ('C','Credit','2024-01-22',500); select * from balance; Happy Querying #sql #data #dataanalytics #dataanalyst #analysis #analyst #dataengineers #dataengineering #machinelearning #datascience #datascientist #machinelearningengineer #businessanalyst #businessanalyticsjobs #businessanalytics #sqlserver #sqltips #sqlforbeginners #postgres #postgresql #mssqlserver #mssql #oracle #mysql #mysqltutorials #database #databasedesign #databasemanagement

Download

1 formats

Video Formats

360pmp46.4 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Window FRAMES in SQL | Difference in ROWS and RANGE | SQL Intermediate Level Interview Question | NatokHD