← SQL workplace practice

Business calendars and period reporting · Original fictional data · Free files and full answers

Reset running revenue at each Monday-start week

Aggregate events per calendar day, then compute running revenue within strftime %Y-%W week. Return day,week_key,week_running_cents for all calendar dates sorted 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

  1. Aggregate events per calendar day, then compute running revenue within strftime %Y-%W week. Return day,week_key,week_running_cents for all calendar dates sorted day.
  2. 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.
  3. 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, week_key, week_running_cents. Sort order follows the task. Output has 15 rows; an empty CSV field means NULL.

Source data

calendar

15 source rows · Download calendar CSV

day TEXTholiday INTEGER
2026-11-010
2026-11-020
2026-11-031
2026-11-040
2026-11-050
2026-11-060
2026-11-070
2026-11-080
2026-11-090
2026-11-100
2026-11-111
2026-11-120
2026-11-130
2026-11-140
2026-11-150

daily

6 source rows · Download daily CSV

day TEXTcents INTEGER
2026-11-01100
2026-11-03200
2026-11-0350
2026-11-070
2026-11-11300
2026-11-15400

cases

4 source rows · Download cases CSV

id INTEGERopened TEXTbirthday TEXT
12026-11-012000-02-29
22026-11-031990-06-10
32026-11-061984-02-29
42026-11-131995-12-01

fiscal_dates

6 source rows · Download fiscal_dates CSV

day TEXT
2026-03-31
2026-04-01
2026-12-31
2027-01-01
2027-03-31
2027-04-01
Field dictionary and schema
calendar:
  day TEXT — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics.
  holiday INTEGER — 1 means an explicitly closed holiday,0 otherwise.

daily:
  day TEXT — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics.
  cents INTEGER — Signed integer currency cents.

cases:
  id INTEGER — Stable source record identifier; not a row position.
  opened TEXT — ISO case opening date.
  birthday TEXT — ISO date used to demonstrate the stated anniversary policy.

fiscal_dates:
  day TEXT — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics.

Download complete SQLite setup

A method you can reuse

  1. Aggregate events per calendar day, then compute running revenue within strftime %Y-%W week. Return day,week_key,week_running_cents for all calendar dates sorted day.
  2. For the first output record, day = 2026-11-01; week_key = 2026-43; week_running_cents = 100.
  3. 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 single lifetime running sum never resets at the required business reporting boundary.

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 x AS (SELECT c.day,strftime('%Y-%W',c.day) week_key,COALESCE(SUM(d.cents),0) revenue FROM calendar c LEFT JOIN daily d ON d.day=c.day GROUP BY c.day) SELECT day,week_key,SUM(revenue) OVER(PARTITION BY week_key ORDER BY day ROWS UNBOUNDED PRECEDING) week_running_cents FROM x ORDER BY day;
"day","week_key","week_running_cents"
"2026-11-01","2026-43","100"
"2026-11-02","2026-44","0"
"2026-11-03","2026-44","250"
"2026-11-04","2026-44","250"
"2026-11-05","2026-44","250"
"2026-11-06","2026-44","250"
"2026-11-07","2026-44","250"
"2026-11-08","2026-44","250"
"2026-11-09","2026-45","0"
"2026-11-10","2026-45","0"
"2026-11-11","2026-45","300"
"2026-11-12","2026-45","300"
"2026-11-13","2026-45","300"
"2026-11-14","2026-45","300"
"2026-11-15","2026-45","700"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects