AlgoMaster Logo

Exercise: Running Totals and Cumulative Calculations

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Write a query that returns each user's username and a running total of their completed payment amount ordered by payment_date. Show usernamepayment_dateamount, and running_total. Order by user_id, then payment_date.

SQL

Expected Query

Expected Output

Exercise 2

Medium

Write a query that returns the running total of completed payment amount across the whole platform, ordered by payment_date. Show payment_date, the day's daily_revenue, and cumulative_revenue. Order by payment_date.

SQL

Expected Query

Expected Output

Exercise 3

Hard

Write a query that returns the running total of amount per user that resets at the start of each calendar month. Show usernamepayment_datemonthamount, and month_running (the running total inside the month, per user). Order by user_id, then payment_date.

SQL

Expected Query

Expected Output