使用sql group by和having

时间:2014-09-16 02:03:41

标签: group-by having-clause

我对SQL很陌生,我正在尝试回答SQL ZOO的练习8,但我遗漏了一些东西。你能帮我吗?

List the continents that have a total population of at least 100 million.

我正在尝试的是:

select continent
from world
group by continent 
having count(population) >= 100000000

3 个答案:

答案 0 :(得分:1)

您的错误是使用COUNT而不是SUM。

尝试以下方法:

select continent
from world
group by continent
having sum(population) >= 100000000

答案 1 :(得分:0)

SELECT continent, SUM(population) AS 'total population'
  FROM world
  GROUP BY continent
  HAVING SUM(population) >= 500000000

答案 2 :(得分:0)

SELECT continent
FROM world
GROUP BY continent
HAVING SUM(population) >= 100000000

请试试这个块