Reputation: 11
European city which population is closest for defect to the median of European population?
I try with this code, but I always have an error with the where condition in the subquery
Select city.name,city.population from city
join country
on city.countrycode=country.code and country.continent='europe'
where city.population<(
avg(country.population)
where country.continent='europe')
order by city.population desc;
Upvotes: 1
Views: 1510
Reputation: 11
Ok, i find out the solution, my mistake was repeating the where clause meanwhile i already declared it in the join:
Select city.name,city.population from city
Join country
On city.countrycode=country.code and country.continent=’europe’
Where (select avg(country.population))>city.population
Order by city.population desc
Limit 1;
Upvotes: 0
Reputation: 31
Select city.name,city.population from city
join country
on city.countrycode=country.code and country.continent='europe'
where city.population < (select avg(country.population)
where country.continent='europe')
order by city.population desc;
Upvotes: 1