Recursive structures · Original fictional data · Free files and full answers
Explode component quantities through every assembly path
For one KIT, recursively multiply quantities along paths and sum repeated leaf components. Return component,required_units for leaves only, sorted component.
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 one KIT, recursively multiply quantities along paths and sum repeated leaf components. Return component,required_units for leaves only, sorted component.
- 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 component, required_units. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.
Source data
nodes
10 source rows · Download nodes CSV
| id INTEGER | parent INTEGER | cost INTEGER |
|---|---|---|
| 1 | NULL | 5 |
| 2 | 1 | 10 |
| 3 | 1 | 20 |
| 4 | 2 | 3 |
| 5 | 2 | 4 |
| 6 | 3 | 8 |
| 7 | 4 | 2 |
| 8 | NULL | 6 |
| 9 | 8 | 9 |
| 10 | 9 | 1 |
edges
8 source rows · Download edges CSV
| src INTEGER | dst INTEGER | weight INTEGER |
|---|---|---|
| 1 | 2 | 3 |
| 1 | 3 | 8 |
| 2 | 3 | 2 |
| 2 | 4 | 7 |
| 3 | 4 | 1 |
| 4 | 2 | 2 |
| 4 | 5 | 4 |
| 6 | 7 | 1 |
parts
6 source rows · Download parts CSV
| parent TEXT | child TEXT | qty INTEGER |
|---|---|---|
| KIT | FRAME | 1 |
| KIT | WHEEL | 2 |
| FRAME | BOLT | 4 |
| FRAME | BAR | 2 |
| WHEEL | BOLT | 3 |
| WHEEL | RIM | 1 |
Field dictionary and schema
nodes: id INTEGER — Stable record or business key; retain its declared type. parent INTEGER — Exact integer measurement; use the task rule for units and ordering. cost INTEGER — Exact integer measurement; use the task rule for units and ordering. edges: src INTEGER — Exact integer measurement; use the task rule for units and ordering. dst INTEGER — Exact integer measurement; use the task rule for units and ordering. weight INTEGER — Exact integer measurement; use the task rule for units and ordering. parts: parent TEXT — Literal text label or key; comparisons use SQLite binary text semantics. child TEXT — Literal text label or key; comparisons use SQLite binary text semantics. qty INTEGER — Exact integer measurement; use the task rule for units and ordering.
A method you can reuse
- For one KIT, recursively multiply quantities along paths and sum repeated leaf components. Return component,required_units for leaves only, sorted component.
- 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
Deduplicating a shared leaf before summing drops the units required through a second assembly path.
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 b(component,n) AS (SELECT child,qty FROM parts WHERE parent='KIT' UNION ALL SELECT p.child,b.n*p.qty FROM b JOIN parts p ON p.parent=b.component) SELECT component,SUM(n) required_units FROM b WHERE NOT EXISTS(SELECT 1 FROM parts p WHERE p.parent=b.component) GROUP BY component ORDER BY component;
"component","required_units" "BAR","2" "BOLT","10" "RIM","2"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects