← SQL workplace practice

Reliable and fair dispatch queues · Original fictional data · Free files and full answers

Reconcile queued work by tenant and age bucket

At20 classify queued wait<10 as recent, otherwise aged. Return tenant,recent_jobs,aged_jobs,total_jobs sorted tenant. Age=20-created.

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. At20 classify queued wait<10 as recent, otherwise aged. Return tenant,recent_jobs,aged_jobs,total_jobs sorted tenant. Age=20-created.
  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 tenant, recent_jobs, aged_jobs, total_jobs. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.

Source data

jobs

9 source rows · Download jobs CSV

id INTEGERtenant TEXTpriority INTEGERcreated INTEGERstatus TEXTlease_until INTEGERattempts INTEGERlast_attempt INTEGERskill TEXT
1A30queuedNULL0NULLcpu
2A22running2515gpu
3A15queuedNULL210cpu
4B31queuedNULL0NULLgpu
5B13running15310cpu
6B24queuedNULL312cpu
7C20queuedNULL118cpu
8C38doneNULL112gpu
9C19queuedNULL0NULLgpu

dependencies

4 source rows · Download dependencies CSV

job_id INTEGERneeds_id INTEGER
32
48
65
94

workers

2 source rows · Download workers CSV

id TEXTskill TEXT
W1cpu
W2gpu
Field dictionary and schema
jobs:
  id INTEGER — Stable source record identifier; not a row position.
  tenant TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  priority INTEGER — Higher integer means higher priority in this case.
  created INTEGER — Exact integer business measurement. Its specific business rule and eligibility are declared in the task.
  status TEXT — Literal lifecycle label; use only statuses eligible in the task.
  lease_until INTEGER — Exclusive UTC minute until which running ownership remains valid.
  attempts INTEGER — Number of attempts already made.
  last_attempt INTEGER — UTC minute of most recent attempt, NULL if never attempted.
  skill TEXT — Literal business key or category label. Match exactly and retain NULL where present.

dependencies:
  job_id INTEGER — Foreign business-record identifier; match to the named source key.
  needs_id INTEGER — Foreign business-record identifier; match to the named source key.

workers:
  id TEXT — Stable source record identifier; not a row position.
  skill TEXT — Literal business key or category label. Match exactly and retain NULL where present.

Download complete SQLite setup

A method you can reuse

  1. At20 classify queued wait<10 as recent, otherwise aged. Return tenant,recent_jobs,aged_jobs,total_jobs sorted tenant. Age=20-created.
  2. For the first output record, tenant = A; recent_jobs = 0; aged_jobs = 2; total_jobs = 2.
  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

Including running jobs inflates the dispatch backlog with work that is already in progress.

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
SELECT tenant,SUM(20-created<10) recent_jobs,SUM(20-created>=10) aged_jobs,COUNT(*) total_jobs FROM jobs WHERE status='queued' GROUP BY tenant ORDER BY tenant;
"tenant","recent_jobs","aged_jobs","total_jobs"
"A","0","2","2"
"B","0","2","2"
"C","0","2","2"
Reference SQL · Complete expected CSV · Empty answer CSV

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