Write SQL and Python, run instantly in your browser, and track your progress.
You are a Finance Analyst at Max. The Revenue team wants to track payment amount changes over time. Calculate the difference between each payment and the previous payment, ordered by payment_id.
| Column Name | Type |
|---|---|
| payment_id | int64 |
| user_id | int64 |
| amount | float64 |
| status | object |
You are a Finance Analyst at Max. The Revenue team wants to track payment amount changes over time. Calculate the difference between each payment and the previous payment, ordered by payment_id.
| Column Name | Type |
|---|---|
| payment_id | int64 |
| user_id | int64 |
| amount | float64 |
| status | object |
| payment_id | user_id | amount | status |
|---|---|---|---|
| 1 | 101 | 15.99 | captured |
| 2 | 102 | 22.99 | captured |
| 3 | 103 | 15.99 | captured |
| payment_id | user_id | amount | status |
|---|---|---|---|
| 1 | 101 | 15.99 | captured |
| 2 | 102 | 22.99 | captured |
| 3 | 103 | 15.99 | captured |
| payment_id | amount | amount_change |
|---|---|---|
| 1 | 17.78 | NaN |
| 2 | 13.31 | -4.47 |
| 3 | 13.64 | 0.33 |
| 4 | 19.92 | 6.28 |
| 5 | 16.10 | -3.82 |
| payment_id | amount | amount_change |
|---|---|---|
| 1 | 17.78 | NaN |
| 2 | 13.31 | -4.47 |
| 3 | 13.64 | 0.33 |
| 4 | 19.92 | 6.28 |
| 5 | 16.10 | -3.82 |
Showing first 5 of 157 rows.
Showing first 5 of 157 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output:
| 4 | 104 | 29.99 | captured |
| 4 | 104 | 29.99 | captured |
| 5 | 105 | 15.99 | refunded |
| 5 | 105 | 15.99 | refunded |