SQL QuestSQL Interview Questions › Subqueries & CTEs

Running Total Revenue

HardFreeQuerying BasicsSubqueries & CTEsWindow FunctionsAggregation & Grouping

Write a SQL query to calculate the running total of revenue by order date. Return order_date, daily revenue, and cumulative revenue up to that date. Order by order_date.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

orders

order_idcustomer_idproductcategoryquantitypricetotalorder_datecountrystatus
11Laptop ProElectronics11299.991299.992024-01-15USAcompleted
22Wireless MouseElectronics249.9999.982024-01-16Canadacompleted
33Office ChairFurniture1349.99349.992024-01-17USAcompleted

Expected output: Daily revenue with running cumulative total

Hint

Use a subquery to get daily totals first, then apply SUM() OVER (ORDER BY order_date) for the running total

Concepts

SELECT Subquery Window Functions GROUP BY Aggregation ORDER BY Window Function

Practise the topic: SQL practice questions · CTE practice · Window function practice · GROUP BY exercises · Advanced SQL interview questions

In these company practice sets

Airbnb · Amazon · JPMorgan · Morgan Stanley · NVIDIA · Ramp · Revolut · Snowflake · Stripe · Tesla · Uber · Goldman Sachs

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Cumulative Distinct Customers Over TimeHard · FreeYear-over-Year GrowthHard · Free7-Day Rolling Revenue AverageHard · FreeMulti-CTE Revenue PipelineHard · FreeWealthy Survivor ProfileHard · ProOrder Sessionization by CustomerHard · Pro

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test