← 返回 nvidia 的题目列表SQL Aggregation Across Country/State/City/Zip Tables
类型:online_judge
Given four tables: country, state, city, and zip.
The zip table contains a population column.
You need to query the total population for a given city name by summing populations across all ZIP codes belonging to that city.
Write an SQL query that returns:
city_name
total_population
Requirements/assumptions:
Use appropriate JOINs to connect zip to city (and to state/country if needed).
Treat identical city_name values as the same city for aggregation (or explain how to disambiguate).
Order results by total_population descending.
Note: the original prompt did not specify columns/keys; state your assumed PK/FK columns (e.g., city.id, zip.city_id).