Write SQL and Python, run instantly in your browser, and track your progress.
You are a Revenue Operations Analyst at Stripe. The Finance team needs to analyze billing period lengths to identify inconsistencies. Calculate the number of days in each invoice's billing period (from period_start to period_end) and find the average period length by status.
| Column Name | Type |
|---|---|
| invoice_id | int64 |
| subscription_id | int64 |
| invoice_number | object |
| period_start |
You are a Revenue Operations Analyst at Stripe. The Finance team needs to analyze billing period lengths to identify inconsistencies. Calculate the number of days in each invoice's billing period (from period_start to period_end) and find the average period length by status.
| Column Name | Type |
|---|---|
| invoice_id | int64 |
| subscription_id | int64 |
| invoice_number | object |
| period_start |
| object |
| object |
| period_end | object |
| period_end | object |
| status | object |
| status | object |
| total_cents | int64 |
| total_cents | int64 |
| invoice_id | subscription_id | invoice_number | period_start | period_end | status | total_cents |
|---|---|---|---|---|---|---|
| 1 | 1 | INV-2025000001 | 2025-03-21 | 2025-04-19 | paid | 0 |
| 2 |
| invoice_id | subscription_id | invoice_number | period_start | period_end | status | total_cents |
|---|---|---|---|---|---|---|
| 1 | 1 | INV-2025000001 | 2025-03-21 | 2025-04-19 | paid | 0 |
| 2 |
| status | avg_period_days | invoice_count |
|---|---|---|
| draft | 76.86 | 7 |
| open | 206.50 | 6 |
| overpaid | 29 | 3 |
| paid | 130.07 | 56 |
| past_due | 127.75 | 12 |
| status | avg_period_days | invoice_count |
|---|---|---|
| draft | 76.86 | 7 |
| open | 206.50 | 6 |
| overpaid | 29 | 3 |
| paid | 130.07 | 56 |
| past_due | 127.75 | 12 |
Showing first 5 of 8 rows.
Showing first 5 of 8 rows.
1. Data Selection:
2. DateTime Operations:
3. Output:
1. Data Selection:
2. DateTime Operations:
3. Output:
| 1 |
| 1 |
| INV-2025000002 |
| INV-2025000002 |
| 2025-04-20 |
| 2025-04-20 |
| 2025-05-19 |
| 2025-05-19 |
| open |
| open |
| 0 |
| 0 |
| 3 | 1 | INV-2025000003 | 2025-05-20 | 2025-06-18 | paid | 0 |
| 3 | 1 | INV-2025000003 | 2025-05-20 | 2025-06-18 | paid | 0 |
| 4 | 2 | INV-2025000004 | 2025-04-24 | 2025-05-23 | past_due | 591690 |
| 4 | 2 | INV-2025000004 | 2025-04-24 | 2025-05-23 | past_due | 591690 |
| 5 | 2 | INV-2025000005 | 2025-05-24 | 2025-06-22 | paid | 537900 |
| 5 | 2 | INV-2025000005 | 2025-05-24 | 2025-06-22 | paid | 537900 |