sqlzoo:using group by and having

博客主要围绕SQL查询展开,涉及按大洲统计国家数量、总人口。介绍了WHERE和GROUP BY的使用,WHERE在聚合函数前过滤;还提及GROUP BY和HAVING,HAVING在GROUP BY后测试,可对聚合值进行测试,如统计特定人口条件下的国家数和大洲总人口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

For each continent show the number of countries:

SELECT continent, COUNT(name)
  FROM world
 GROUP BY continent

For each continent show the total population:

SELECT continent, SUM(population)
  FROM world
 GROUP BY continent

WHERE and GROUP BY. The WHERE filter takes place before the aggregating function.

For each relevant continent show the number of countries that has a population of at least 200000000.

SELECT continent, COUNT(name)
  FROM world
 WHERE population>200000000
 GROUP BY continent

GROUP BY and HAVING. The HAVING clause is tested after the GROUP BY. You can test the aggregated values with a HAVING clause.

Show the total population of those continents with a total population of at least half a billion.

SELECT continent, SUM(population)
  FROM world
 GROUP BY continent
HAVING SUM(population)>500000000

 

转载于:https://www.cnblogs.com/yellowduck/p/10560166.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值