Intervals and scheduling · Original fictional data · Free files and full answers
Allocate contested time to the highest priority
Split each resource at every start/end. For every occupied elementary segment choose highest priority, then smallest booking id. Output resource,start,end,winner_id; do not merge adjacent segments. Sort resource,start.
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
- Split each resource at every start/end. For every occupied elementary segment choose highest priority, then smallest booking id. Output resource,start,end,winner_id; do not merge adjacent segments. Sort resource,start.
- Return exactly the declared columns and order. Money uses integer cents; all time values are elapsed UTC minutes unless a field is explicitly a day index. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. All source tables in this case are included in the downloadable pack.
Return columns exactly as resource, start, end, winner_id. Sort order follows the task. Output has 15 rows; an empty CSV field means NULL.
Source data
slots
12 source rows · Download slots CSV
| id INTEGER | resource TEXT | start INTEGER | end INTEGER | priority INTEGER |
|---|---|---|---|---|
| 1 | R1 | 0 | 20 | 1 |
| 2 | R1 | 10 | 30 | 3 |
| 3 | R1 | 30 | 40 | 2 |
| 4 | R1 | 50 | 60 | 1 |
| 5 | R1 | 12 | 18 | 4 |
| 6 | R2 | 5 | 15 | 1 |
| 7 | R2 | 20 | 35 | 2 |
| 8 | R2 | 30 | 45 | 1 |
| 9 | R2 | 45 | 50 | 3 |
| 10 | R3 | 0 | 10 | 1 |
| 11 | R3 | 15 | 25 | 1 |
| 12 | R3 | 40 | 60 | 2 |
requests
5 source rows · Download requests CSV
| id INTEGER | resource TEXT | minute INTEGER | duration INTEGER |
|---|---|---|---|
| 1 | R1 | 5 | 8 |
| 2 | R1 | 41 | 7 |
| 3 | R2 | 16 | 5 |
| 4 | R3 | 26 | 10 |
| 5 | R1 | 45 | 8 |
Field dictionary and schema
slots: id INTEGER — Stable record or business key; retain its declared type. resource TEXT — Literal text label or key; comparisons use SQLite binary text semantics. start INTEGER — Exact integer measurement; use the task rule for units and ordering. end INTEGER — Exact integer measurement; use the task rule for units and ordering. priority INTEGER — Exact integer measurement; use the task rule for units and ordering. requests: id INTEGER — Stable record or business key; retain its declared type. resource TEXT — Literal text label or key; comparisons use SQLite binary text semantics. minute INTEGER — Exact integer measurement; use the task rule for units and ordering. duration INTEGER — Exact integer measurement; use the task rule for units and ordering.
A method you can reuse
- Split each resource at every start/end. For every occupied elementary segment choose highest priority, then smallest booking id. Output resource,start,end,winner_id; do not merge adjacent segments. Sort resource,start.
- Inspect the source grain, keys and ties before writing the query. Use the worked SQL and complete expected CSV to review any mismatch.
Watch for this wrong turn
Picking the highest-priority booking once per resource discards its changing availability over time.
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 p AS (SELECT resource,start p FROM slots UNION SELECT resource,end FROM slots), x AS (SELECT resource,p start,LEAD(p) OVER(PARTITION BY resource ORDER BY p) end FROM p), r AS (SELECT x.*,s.id,ROW_NUMBER() OVER(PARTITION BY x.resource,x.start ORDER BY priority DESC,s.id) n FROM x JOIN slots s ON s.resource=x.resource AND s.start<=x.start AND s.end>x.start WHERE x.end IS NOT NULL) SELECT resource,start,end,id winner_id FROM r WHERE n=1 ORDER BY resource,start;
"resource","start","end","winner_id" "R1","0","10","1" "R1","10","12","2" "R1","12","18","5" "R1","18","20","2" "R1","20","30","2" "R1","30","40","3" "R1","50","60","4" "R2","5","15","6" "R2","20","30","7" "R2","30","35","7" "R2","35","45","8" "R2","45","50","9" "R3","0","10","10" "R3","15","25","11" "R3","40","60","12"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects