Sql Join with subquery

Screen Link:

My Code:

SELECT name,urban_pop,facts.population as total_pop,Round(cast(urban_pop as float)/facts.population,6) as urban_pct from facts join (SELECT facts_id,SUM(population) as urban_pop from cities group by facts_id) as city on facts.id=city.facts_id where urban_pct>0.5 ORDER by urban_pct ASC

What I expected to happen:
A table consisting of country name, urban population, total population and percentage of population as shown in the question

What actually happened:
I got the same result as expected but it doesn’t accept the submission

I haven’t tested it out, but as per the instructions -

The following columns, in order:

  • country , the name of the country.

The column name should be country, but you have kept it as name. That’s probably the only difference, I think.

1 Like

Yes, thanks for pointing it out. It worked when I added ‘country’ as alias.