Menu
hardShopee · window

Running total of daily sales

Shopee's finance team wants a cumulative view of sales during a campaign.

From the daily_sales table, return each sale_date, its amount, and the running total of amount ordered by date as running_total. Order the output by sale_date.

Schema

daily_sales
sale_dateDATE
amountNUMERIC(10,2)

Example input

daily_sales
↑ Read the question

The interviewer's next question

Nice — the running total works. Now add a column showing each day's amount as a percentage of the whole campaign's total (pct_of_total), rounded to one decimal place.

Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.

See Basic plans

RM 25/mo · cancel anytime

The team also wants to see momentum: for each day after the first, how much sales changed versus the previous day, in currency (change_from_prev). The first day should show NULL.

Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.

See Basic plans

RM 25/mo · cancel anytime

Keep going

Company names are trademarks of their respective owners, used here only to describe practice material. mahir_data is not affiliated with, endorsed by, or sponsored by any company named on this site. Terms.