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
相关推荐
阿华的代码王国22 分钟前
MySQL ------- 索引(B树B+树)
数据库·mysql
Hello.Reader1 小时前
StarRocks实时分析数据库的基础与应用
大数据·数据库
执键行天涯1 小时前
【经验帖】JAVA中同方法,两次调用Mybatis,一次更新,一次查询,同一事务,第一次修改对第二次的可见性如何
java·数据库·mybatis
liupenglove1 小时前
golang操作mysql利器-gorm
mysql·golang
yanglamei19621 小时前
基于GIKT深度知识追踪模型的习题推荐系统源代码+数据库+使用说明,后端采用flask,前端采用vue
前端·数据库·flask
Darling_001 小时前
LeetCode_sql_day28(1767.寻找没有被执行的任务对)
sql·算法·leetcode
zxrhhm1 小时前
SQLServer TOP(Transact-SQL)
sql·sqlserver
叫我:松哥1 小时前
基于Python flask的医院管理学院,医生能够增加/删除/修改/删除病人的数据信息,有可视化分析
javascript·后端·python·mysql·信息可视化·flask·bootstrap
工作中的程序员1 小时前
ES 索引或索引模板
大数据·数据库·elasticsearch
严格格1 小时前
三范式,面试重点
数据库·面试·职场和发展