SQL Zoo 5.SUM and COUNT

以下题目均来自sql zoo

1.Show the total population of the world.(显示世界总人口)

sql 复制代码
select sum(population) from world

2.List all the continents - just once each.(列出所有的大洲------每个只列出一个)

sql 复制代码
select distinct(continent) from world

解:distinct用来查询不重复记录的条数

3.Give the total GDP of Africa.(非洲的GDP总量)

sql 复制代码
select sum(gdp) from world where continent = 'africa'

4.How many countries have an area of at least 1000000.(列出面积至少有100万的国家)

sql 复制代码
select count(name) from world where area >=1000000

解:COUNT() 函数返回匹配指定条件的行数

5.What is the total population of ('Estonia', 'Latvia', 'Lithuania')(求出爱沙尼亚、拉脱维亚、立陶宛的总人口)

sql 复制代码
select sum(population) from world where name in 
('Estonia', 'Latvia', 'Lithuania')

6.For each continent show the continent and number of countries.(对于每个洲,显示洲和国家数量)

sql 复制代码
select continent,count(name) from world group by continent

7.For each continent show the continent and number of countries with populations of at least 10 million.(对于每个洲,请显示人口至少为1000万的洲和国家数目)

sql 复制代码
select continent,count(name) from world 
where population >=10000000 group by continent

8.List the continents that have a total population of at least 100 million.(列出人口总数超过1亿的大洲)

sql 复制代码
select continent from world group by continent 
having sum(population) >=100000000
相关推荐
ClickHouseDB2 小时前
ClickHouse Cloud 与 Snowflake 实时性价比对比:CostBench 测试中的 412 倍差距来
运维·数据库·系统架构
m0_639906942 小时前
Redis入门|五种数据结构、使用场景、持久化RDB&AOF
数据结构·数据库·redis
时间售卖铺3 小时前
触发器与函数实战:MySQL高效编程秘诀
运维·数据库·mysql·云原生
qetfw3 小时前
UOS MariaDB 数据库:安装、最小权限与备份验证
linux·数据库·mariadb·uos
数智园区合作社4 小时前
问数平台怎么把同一个指标锁成一个数
大数据·数据库·人工智能·ai
lbb 小魔仙4 小时前
Windows搭建PaddleOCR+飞书Webhook自动打卡通知机器人:识别、推送与远程触发完整教程
数据库·人工智能·prometheus·时序数据库
captain3765 小时前
MyBatis操作数据库(入门2)
java·数据库·spring boot·后端·spring·mybatis
心中有你02146 小时前
Java实现Dijkstra最短路径算法(邻接表 + 优先队列)
java·数据库·算法
龙亘川6 小时前
综合素质评价业务建模:从过程性评价到成长档案全链路闭环
数据库·智慧城市·数据可视化
数据库小组6 小时前
NineData 实战教程:MySQL 5.5 数据迁移同步到 MySQL 8.0(跨版本升级)
数据库·mysql·mysql优化·数据库开发·数据库迁移·版本升级·数据复制