1

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;

2 Answers2

1
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;
Saba Shafi
  • 31
  • 3
0

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;