Write SQL and Python, run instantly in your browser, and track your progress.
You are a Business Analyst at Shopify. The Sales team wants to track recent revenue momentum by calculating a rolling sum of the last 3 orders. Calculate a 3-order rolling sum of total_amount, ordered by order_id.
| Column Name | Type |
|---|---|
| order_id | int64 |
| order_number | object |
| total_amount | float64 |
| status | object |
You are a Business Analyst at Shopify. The Sales team wants to track recent revenue momentum by calculating a rolling sum of the last 3 orders. Calculate a 3-order rolling sum of total_amount, ordered by order_id.
| Column Name | Type |
|---|---|
| order_id | int64 |
| order_number | object |
| total_amount | float64 |
| status | object |
| order_id | order_number | total_amount | status |
|---|---|---|---|
| 1 | ORD-001 | 150.00 | delivered |
| 2 | ORD-002 | 200.00 | delivered |
| 3 | ORD-003 | 100.00 |
| order_id | order_number | total_amount | status |
|---|---|---|---|
| 1 | ORD-001 | 150.00 | delivered |
| 2 | ORD-002 | 200.00 | delivered |
| 3 | ORD-003 | 100.00 |
| order_id | order_number | total_amount | rolling_revenue |
|---|---|---|---|
| 1 | ORD-10001 | 55.32 | NaN |
| 2 | ORD-10002 | 662.48 | NaN |
| 3 | ORD-10003 | 88.66 | 806.46 |
| 4 | ORD-10004 | 322.87 | 1074.01 |
| order_id | order_number | total_amount | rolling_revenue |
|---|---|---|---|
| 1 | ORD-10001 | 55.32 | NaN |
| 2 | ORD-10002 | 662.48 | NaN |
| 3 | ORD-10003 | 88.66 | 806.46 |
| 4 | ORD-10004 | 322.87 | 1074.01 |
Showing first 5 of 75 rows.
Showing first 5 of 75 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output:
| shipped |
| shipped |
| 4 | ORD-004 | 250.00 | delivered |
| 4 | ORD-004 | 250.00 | delivered |
| 5 | ORD-005 | 175.00 | shipped |
| 5 | ORD-005 | 175.00 | shipped |
| 5 | ORD-10005 | 629.34 | 1040.87 |
| 5 | ORD-10005 | 629.34 | 1040.87 |