Итак, это работает:
SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population, ROUND(100*(SUM(ci.population)/c.population)) AS city_population_percent
FROM country AS c
JOIN city AS ci
ON c.code = ci.countrycode
WHERE c.continent = 'Europe'
GROUP BY c.name
Но мне нужно только захватить значения city_population_percent больше 30, поэтому я пробую это:
SELECT c.name AS country_name, c.population AS country_population, SUM(ci.population) AS city_population, ROUND(100*(SUM(ci.population)/c.population)) AS city_population_percent
FROM country AS c
JOIN city AS ci
ON c.code = ci.countrycode
WHERE c.continent = 'Europe'
**AND ROUND(100*(SUM(ci.population)/c.population)) > 30**
GROUP BY c.name
И когда я получу:
Код ошибки 1111. Недопустимое использование групповой функции
То есть, он терпит неудачу, когда я добавляю это условие в WHERE
:
AND ROUND(100*(SUM(ci.population)/c.population)) > 30