使用Group By和Having的SQL查询

时间:2017-11-30 06:40:42

标签: sql

我正在与this table合作,我找不到如何回答这个问题:

  

列出总人口至少为100的大陆   万美元。

我如何“列出”各大洲并计算每个大陆的人口总数。我做了一些试验,但语法错误。 像:

SELECT continent from world
HAVING SUM(population) > = 100000000

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您需要GROUP BY子句才能使用HAVING子句。

修改后的查询将是

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