MP3JOSS

SQL Quick Tip: Calculate Cumulative Sums with Ease! #sql #interview #sqltips #database

SQL Quick Tip: Calculate Cumulative Sums with Ease! #sql #interview #sqltips #database

Choose Download Format

Download MP3 Download MP4

Details

TitleSQL Quick Tip: Calculate Cumulative Sums with Ease! #sql #interview #sqltips #database
AuthorDesk For Dev
Duration0:07
File FormatMP3 / MP4
Original URL https://youtube.com/watch?v=UKu0WnLkaAQ

Description

For each row in the employees table, the SUM(salary) OVER (ORDER BY id) function computes the sum of salary from the beginning of the dataset up to the current row, based on the ordering by id.
This creates a cumulative or running total of the salary column.

Explanation of Output:

Row 1: The cumulative sum is just the salary of id 1, which is 30,000.
Row 2: The cumulative sum is 30,000 + 45,000 = 75,000.
Row 3: The cumulative sum is 75,000 + 50,000 = 125,000.
Row 4: The cumulative sum is 125,000 + 55,000 = 180,000.
Row 5: The cumulative sum is 180,000 + 40,000 = 220,000.

🎧 Just For You

🎵 Someone Like You - Adele 🎵 Bundy Vision - Media Puzzle 🎵 Anxiety - Doechii 🎵 Die With A Smile - Lady Gaga & Bruno Mars 🎵 Golden - Huntr/X 🎵 Catch These Fists - Wet Leg 🎵 Pink Pony Club - Chappell Roan 🎵 Forever Young - David Guetta, Alphaville… 🎵 Azizam - Ed Sheeran 🎵 Grenade - Bruno Mars 🎵 Midnight Sun - Zara Larsson 🎵 Dior - Mk & Chrystal