Subscription service and billing · Original fictional data · Free files and full answers
Report active paid recurring revenue by calendar day
For every day0..29 return day,active_contracts,daily_revenue_cents from paid entitled service at that day. Cancellation day itself is excluded. Sort day.
Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.
Your output contract
- For every day0..29 return day,active_contracts,daily_revenue_cents from paid entitled service at that day. Cancellation day itself is excluded. Sort day.
- Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.
Return columns exactly as day, active_contracts, daily_revenue_cents. Sort order follows the task. Output has 30 rows; an empty CSV field means NULL.
Source data
contracts
6 source rows · Download contracts CSV
| id INTEGER | start_day INTEGER | end_day INTEGER | seats INTEGER | daily_cents INTEGER | trial_end INTEGER | cancel_day INTEGER |
|---|---|---|---|---|---|---|
| 1 | 0 | 30 | 2 | 100 | 3 | NULL |
| 2 | 5 | 20 | 1 | 150 | 5 | 15 |
| 3 | 10 | 40 | 3 | 80 | 12 | NULL |
| 4 | 0 | 10 | 1 | 200 | 0 | 8 |
| 5 | 20 | 30 | 2 | 120 | 25 | NULL |
| 6 | 0 | 60 | 1 | 50 | 0 | NULL |
usage
9 source rows · Download usage CSV
| id INTEGER | contract_id INTEGER | day INTEGER | units INTEGER |
|---|---|---|---|
| 1 | 1 | 3 | 40 |
| 2 | 1 | 4 | 80 |
| 3 | 1 | 8 | 20 |
| 4 | 2 | 6 | 50 |
| 5 | 2 | 16 | 10 |
| 6 | 3 | 15 | 250 |
| 7 | 4 | 3 | 0 |
| 8 | 5 | 27 | 80 |
| 9 | 6 | 10 | 120 |
bills
5 source rows · Download bills CSV
| id INTEGER | contract_id INTEGER | start_day INTEGER | end_day INTEGER | cents INTEGER |
|---|---|---|---|---|
| 1 | 1 | 3 | 10 | 1400 |
| 2 | 1 | 12 | 30 | 3600 |
| 3 | 2 | 5 | 15 | 1500 |
| 4 | 4 | 0 | 8 | 1600 |
| 5 | 6 | 0 | 30 | 1500 |
Field dictionary and schema
contracts: id INTEGER — Stable source record identifier; not a row position. start_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation. end_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation. seats INTEGER — Number of paid service seats. daily_cents INTEGER — Contracted cents per seat per day. trial_end INTEGER — First day of paid service, after the free trial. cancel_day INTEGER — Exclusive service end day if cancelled; NULL means no recorded cancellation. usage: id INTEGER — Stable source record identifier; not a row position. contract_id INTEGER — Foreign business-record identifier; match to the named source key. day INTEGER — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics. units INTEGER — Physical unit quantity, not a monetary amount. bills: id INTEGER — Stable source record identifier; not a row position. contract_id INTEGER — Foreign business-record identifier; match to the named source key. start_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation. end_day INTEGER — Day index or ISO date as declared in this task; preserve its source representation. cents INTEGER — Signed integer currency cents.
A method you can reuse
- For every day0..29 return day,active_contracts,daily_revenue_cents from paid entitled service at that day. Cancellation day itself is excluded. Sort day.
- For the first output record, day = 0; active_contracts = 2; daily_revenue_cents = 250.
- Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.
Watch for this wrong turn
A cumulative number of contracts ever signed does not represent current recurring paid service.
Run and check in SQLite
Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.
Complete worked SQL and expected output
WITH RECURSIVE n(day) AS (SELECT 0 UNION ALL SELECT day+1 FROM n WHERE day<29) SELECT day,COUNT(c.id) active_contracts,COALESCE(SUM(c.seats*c.daily_cents),0) daily_revenue_cents FROM n LEFT JOIN contracts c ON day>=MAX(c.start_day,c.trial_end,0) AND day<MIN(c.end_day,COALESCE(c.cancel_day,30),30) GROUP BY day ORDER BY day;
"day","active_contracts","daily_revenue_cents" "0","2","250" "1","2","250" "2","2","250" "3","3","450" "4","3","450" "5","4","600" "6","4","600" "7","4","600" "8","3","400" "9","3","400" "10","3","400" "11","3","400" "12","4","640" "13","4","640" "14","4","640" "15","3","490" "16","3","490" "17","3","490" "18","3","490" "19","3","490" "20","3","490" "21","3","490" "22","3","490" "23","3","490" "24","3","490" "25","4","730" "26","4","730" "27","4","730" "28","4","730" "29","4","730"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects