On the ‘Joining Data in SQL’ course I got a little lost on the challenge question but worked out a solution. Basically I grouped by ‘f.name AS country’ instead of grouping by c.facts_id
My solution worked and as others are likely to perhaps be on the same though process as me I thought I would just post my alternative result.
SELECT f.name AS country, SUM(c.population) AS urban_pop, f.population AS total_pop, (CAST(SUM(c.population) AS float) / CAST(f.population AS float)) AS urban_pct FROM facts AS f INNER JOIN cities as c ON f.id = c.facts_id GROUP BY country HAVING urban_pct > 0.5 ORDER BY urban_pct
This may not be a great alternative solution but maybe it helps other students out a bit with their thinking.
OK, onto the next course