Interview Questions/SQL/Monthly Sales with Running Total

Monthly Sales with Running Total

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Monthly Sales with Running Total

You are given a table of sales records. Each record has an id, a sale date, and an amount. Write a SQL query to return for each calendar month: the total sales amount for that month (monthly_total), and the cumulative running total of all sales up to and including that month (running_total). Return the result ordered by month ascending. Table: Sales

Column NameTypeDescription
idINTPrimary key
sale_dateDATEDate of the sale
amountDECIMALSale amount

Examples

Example 1

January has two sales totalling 800. February has two totalling 900; running total becomes 1700. March has 900; running total becomes 2600.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql