Back to Practice
#0028
Running Revenue By Day
MediumSQL18 min15 XP
Problem
Given daily revenue rows, return each day with cumulative revenue up to that day.
Why This Matters
Running totals show growth over time and are a core analytics dashboard pattern.
Schema
daily_sales(day, revenue)
Examples
Example 1
Inputday 1 revenue 100, day 2 revenue 50, day 3 revenue 200
Output100, 150, 350
Each running value includes all previous days plus the current day.
Constraints
- Return day, revenue, running_revenue.
- Order by day ascending.
- Use a window function.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 4 hidden categories
Three-day running total
Input100, 50, 200
Expected100, 150, 350
The window expands from the first row to the current row.
Hidden Test Categories
One day onlyZero revenue dayUnsorted inserted rowsRepeated revenue values