๐ The CFO Wants a Story, Not a Number.
It is budget review season at PayPal's Finance Analytics team. The CFO has seen the monthly revenue totals. She is unimpressed. She leans forward and says the sentence that separates senior analysts from juniors:
'I don't want snapshots. I want momentum. Show me the running total.'
A running total (also called a cumulative sum) shows not just what each month earned โ but what the business has earned in total up to that point. It tells the story of growth, stagnation, and recovery in a way that isolated monthly figures never can.
Your task: Calculate the monthly revenue AND the running cumulative total, ordered chronologically. Return month, monthly_revenue, and running_total.
The weapon you need is a window functions. Many analysts know SUM(). Almost none know how to use it as a window function without collapsing their result set.
sales Table:
| Column Name | Type |
|---|---|
| sale_id | integer |
| amount | integer |
| sale_date | text |
Expected Outcome (Illustrative Sample):
| month | monthly_revenue | running_total |
|---|---|---|
| 2024-01 | 3200 | 3200 |
Write the query. Give the CFO her story.