Loading problem...
A warehouse analytics team tracks fruit inventory at two container levels.
Table: boxes
Table: chests
Task: Compute the total number of apples and oranges across all boxes.
Counting rules:
Output requirements:
Supported submission environments:
boxes:
| box_id | chest_id | apple_count | orange_count |
|--------|----------|-------------|--------------|
| 1 | null | 5 | 2 |
| 2 | 10 | 4 | 3 |
| 3 | 10 | 1 | 7 |
chests:
| chest_id | apple_count | orange_count |
|----------|-------------|--------------|
| 10 | 6 | 8 |[
{"apple_count":22,"orange_count":28}
]Box 1 contributes only its own fruit. Boxes 2 and 3 each add chest 10 values on top of their own counts.
boxes:
| box_id | chest_id | apple_count | orange_count |
|--------|----------|-------------|--------------|
| 11 | 4 | 0 | 9 |
| 12 | null | 10 | 0 |
| 13 | 8 | 3 | 1 |
chests:
| chest_id | apple_count | orange_count |
|----------|-------------|--------------|
| 4 | 2 | 2 |
| 8 | 5 | 4 |
| 99 | 100 | 100 |[
{"apple_count":20,"orange_count":16}
]Chest 99 is unreferenced and must be ignored. Only chest 4 and chest 8 are added through linked boxes.
boxes:
| box_id | chest_id | apple_count | orange_count |
|--------|----------|-------------|--------------|
| 101 | null | 7 | 3 |
| 102 | null | 0 | 5 |
| 103 | null | 4 | 0 |
chests:
| chest_id | apple_count | orange_count |
|----------|-------------|--------------|
| 50 | 9 | 9 |[
{"apple_count":11,"orange_count":8}
]With all chest_id values null, totals come entirely from the boxes table.
Constraints