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
相关推荐
秋氘渔19 分钟前
智演沙盘 —— 基于大模型的智能面试评估系统
python·mysql·django·drf
Hello.Reader28 分钟前
Flink SQL 的 LOAD MODULE 深度实战——加载 Hive 模块、理解模块发现与常见坑
hive·sql·flink
大猫和小黄31 分钟前
若依微服务全面适配PostgreSQL-OpenGauss数据库
数据库·微服务·postgresql·若依
老徐电商数据笔记38 分钟前
技术复盘第二篇:电商数据主题域划分企业级实践
大数据·数据库·数据仓库·零售·教育电商·技术面试
jfqqqqq39 分钟前
postgres查询、重设自增序列的起始值
数据库·sql·postgres·自增序列
1 小时前
TIDB——PD(placement Driver)
java·数据库·分布式·tidb·
计算机毕设指导61 小时前
基于微信小程序的鸟博士系统【源码文末联系】
java·spring boot·mysql·微信小程序·小程序·tomcat·maven
DemonAvenger1 小时前
Redis与MySQL双剑合璧:缓存更新策略与数据一致性保障
数据库·redis·性能优化
断春风1 小时前
如何避免 MySQL 死锁?——从原理到实战的系统性解决方案
数据库·mysql
闲人编程1 小时前
基础设施即代码(IaC)工具比较:Pulumi vs Terraform
java·数据库·terraform·iac·codecapsule·pulumi