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
| sale_date | DATE |
| amount | NUMERIC(10,2) |
Example input
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.
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 plansRM 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 plansRM 25/mo · cancel anytime