Write SQL and Python, run instantly in your browser, and track your progress.
You are a Revenue Analyst at Stripe. The Finance team wants to compare each invoice to the previous one. Use the shift() function to add a column showing the previous invoice's total_cents value, ordered by invoice_id.
| Column Name | Type |
|---|---|
| invoice_id | int64 |
| status | object |
| total_cents | int64 |
You are a Revenue Analyst at Stripe. The Finance team wants to compare each invoice to the previous one. Use the shift() function to add a column showing the previous invoice's total_cents value, ordered by invoice_id.
| Column Name | Type |
|---|---|
| invoice_id | int64 |
| status | object |
| total_cents | int64 |
| invoice_id | status | total_cents |
|---|---|---|
| 1 | paid | 15000 |
| 2 | paid | 22500 |
| 3 | open | 18000 |
| 4 | paid | 30000 |
| 5 | void | 12000 |
| invoice_id | status | total_cents |
|---|---|---|
| 1 | paid | 15000 |
| 2 | paid | 22500 |
| 3 | open | 18000 |
| 4 | paid | 30000 |
| 5 | void | 12000 |
| invoice_id | total_cents | prev_total |
|---|---|---|
| 1 | 0 | NaN |
| 2 | 0 | 0 |
| 3 | 0 | 0 |
| 4 | 591690 | 0 |
| 5 | 537900 | 591690 |
| invoice_id | total_cents | prev_total |
|---|---|---|
| 1 | 0 | NaN |
| 2 | 0 | 0 |
| 3 | 0 | 0 |
| 4 | 591690 | 0 |
| 5 | 537900 | 591690 |
Showing first 5 of 99 rows.
Showing first 5 of 99 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output: