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
🎵 Support the artists — buy the original for the best audio quality! 🎵

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

🎵 Eternity - Alex Warren 🎵 Irl - Lizzo & Sza 🎵 Shake It To The Max (Fly) - Moliy, Silent… 🎵 Let Her Go - Passenger 🎵 - Emin & Jony 🎵 Golden - Huntr/X, Ejae, Audrey Nuna, Rei… 🎵 Midnight Sun - Zara Larsson 🎵 Be Mine - Kamrad 🎵 Shake It To The Max (Fly) [Remix]… 🎵 Apt. - Ros & Bruno Mars 🎵 Espresso Macchiato - Tommy Cash 🎵 Perfect - Ed Sheeran