My query below produces almost the same result as the provided solution, and the calculations appear to be correct, but a couple of rows are missing from my results.
SELECT countries.name AS country, SUM(cities.population) AS urban_pop, countries.population AS total_pop, CAST(cities.population AS FLOAT) / countries.population AS urban_pct FROM cities INNER JOIN facts AS countries ON cities.facts_id = countries.id WHERE urban_pct > 0.5 GROUP BY countries.id ORDER BY urban_pct;
Here are the first few rows of my results:
And here are the first few expected results:
|Congo, Republic of the||2445000||4755097||0.5141850944365594|
Why is the Congo missing from my version? I know I took a different approach than suggested, but I can’t figure out why the results are different.