
Quiz
Why Did the Total Double?
The quartermaster adds a keepers table: the lighthouse keepers on
each island. Her new report joins three tables. Amber received
exactly 5 crates, but the report says 10!
Data: Amber has one delivery of 5 crates and two keepers (Ada and Moss). Fog has one delivery of 4 crates and one keeper.
rows = conn.execute("""
SELECT i.name, SUM(d.crates), COUNT(k.id)
FROM islands AS i
JOIN deliveries AS d ON d.island_id = i.id
JOIN keepers AS k ON k.island_id = i.id
GROUP BY i.id
ORDER BY i.name
""").fetchall()
print(rows)
# [('Amber', 10, 2), ('Fog', 4, 1)]