Back to Practice
#0364
Rolling Three Day Revenue
HardSQL35 min25 XP
Problem
Return day and rolling_3_revenue using the current row and previous two rows.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
daily_sales(day TEXT, revenue INTEGER)
Examples
Example 1
Inputdaily revenue 10, 20, 30, 40
Output10, 30, 60, 90
Each row sums itself and the previous two rows when available.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputdaily revenue 10, 20, 30, 40
Expected[["2026-01-01",10],["2026-01-02",30],["2026-01-03",60],["2026-01-04",90]]
Each row sums itself and the previous two rows when available.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks