
Checkpoint
Checkpoint: The Quartermaster's Report
The quartermaster wants one report that lists every island, even the forgotten ones. A missing island might mean its lantern is about to go dark!
This checkpoint uses the whole chapter: JOIN, LEFT JOIN,
COUNT, SUM, GROUP BY and HAVING.
One new tool: COALESCE
For an island with no deliveries, SUM(d.crates) has nothing to add,
so it gives NULL. COALESCE(a, b) returns the first value that
isn't NULL, so COALESCE(SUM(d.crates), 0) turns "nothing" into 0.
Assignment
Tables: islands(id, name) and
deliveries(id, island_id, courier, crates).
quartermaster_report(conn)returns a list of(island, deliveries, crates)for every island. Islands with no deliveries show0and0(neverNone). Biggestcratestotal first; ties A to Z by name.idle_islands(conn)returns a list of the names (strings) of islands with no deliveries, A to Z.
The program should print:
[('Gull Rock', 2, 11), ('Amber Isle', 1, 5), ('Fog Reach', 0, 0), ('Teal Cove', 0, 0)]
['Fog Reach', 'Teal Cove']Tables: islands(id, name) and
deliveries(id, island_id, courier, crates).
quartermaster_report(conn)returns a list of(island, deliveries, crates)for every island. Islands with no deliveries show0and0(neverNone). Biggestcratestotal first; ties A to Z by name.idle_islands(conn)returns a list of the names (strings) of islands with no deliveries, A to Z.
The program should print:
[('Gull Rock', 2, 11), ('Amber Isle', 1, 5), ('Fog Reach', 0, 0), ('Teal Cove', 0, 0)]
['Fog Reach', 'Teal Cove']main.py Python sleeping
Press Run to try your code, then Check to test it.