Write SQL and Python, run instantly in your browser, and track your progress.
You are a Revenue Analyst at Snowflake. The Finance team needs to track cumulative revenue over time. Calculate a running total of payment amounts using the expanding window function, ordered by payment_id.
| Column Name | Type |
|---|---|
| payment_id | int64 |
| invoice_id | int64 |
| amount_cents | int64 |
| status | object |
You are a Revenue Analyst at Snowflake. The Finance team needs to track cumulative revenue over time. Calculate a running total of payment amounts using the expanding window function, ordered by payment_id.
| Column Name | Type |
|---|---|
| payment_id | int64 |
| invoice_id | int64 |
| amount_cents | int64 |
| status | object |
| payment_id | invoice_id | amount_cents | status |
|---|---|---|---|
| 1 | 101 | 15000 | succeeded |
| 2 | 102 | 22500 | succeeded |
| 3 | 103 | 18000 |
| payment_id | invoice_id | amount_cents | status |
|---|---|---|---|
| 1 | 101 | 15000 | succeeded |
| 2 | 102 | 22500 | succeeded |
| 3 | 103 | 18000 |
| payment_id | amount_cents | cumulative_total |
|---|---|---|
| 1 | 0 | 0 |
| 2 | 0 | 0 |
| 3 | 251830 | 251830 |
| 4 | 537900 | 789730 |
| 5 | 537900 | 1327630 |
| payment_id | amount_cents | cumulative_total |
|---|---|---|
| 1 | 0 | 0 |
| 2 | 0 | 0 |
| 3 | 251830 | 251830 |
| 4 | 537900 | 789730 |
| 5 | 537900 | 1327630 |
Showing first 5 of 83 rows.
Showing first 5 of 83 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output:
| succeeded |
| succeeded |
| 4 | 104 | 30000 | succeeded |
| 4 | 104 | 30000 | succeeded |
| 5 | 105 | 12000 | failed |
| 5 | 105 | 12000 | failed |