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
相关推荐
时序数据说1 小时前
为什么时序数据库IoTDB选择Java作为开发语言
java·大数据·开发语言·数据库·物联网·时序数据库·iotdb
戒不掉的伤怀1 小时前
【Navicat 连接MySQL时出现错误1251:客户端不支持服务器请求的身份验证协议;请考虑升级MySQL客户端】
服务器·数据库·mysql
cv高级工程师YKY1 小时前
服务器 - - QPS与TPS介绍
数据库
nbsaas-boot2 小时前
高可扩展属性建模设计:架构师的全局思考与落地方案
数据库
爱上语文2 小时前
Redis基础(5):Redis的Java客户端
java·开发语言·数据库·redis·后端
陈敬雷-充电了么-CEO兼CTO3 小时前
推荐算法系统系列>推荐数据仓库集市的ETL数据处理
大数据·数据库·数据仓库·数据挖掘·数据分析·etl·推荐算法
MeshddY3 小时前
(超详细)数据库项目初体验:使用C语言连接数据库完成短地址服务(本地运行版)
c语言·数据库·单片机
wuxinyan1233 小时前
Java面试题033:一文深入了解MySQL(5)
java·数据库·mysql·面试
笑衬人心。3 小时前
Ubuntu 22.04 + MySQL 8 无密码登录问题与 root 密码重置指南
linux·mysql·ubuntu
萧曵 丶3 小时前
Spring @TransactionalEventListener
java·数据库·spring·事务·transactional·异步