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
相关推荐
ACP广源盛139246256732 分钟前
Qwen3.8‑2.4T 开源落地@ACP#国产 MoE 大模型私有化部署中 MST 多屏转换芯片 GSV2231 硬件价值与应用场景
大数据·数据库·人工智能·嵌入式硬件
java_logo2 分钟前
Docker 部署 openGauss:轻松搭建企业级开源关系型数据库平台
数据库·docker·开源·opengauss·轩辕镜像·opengauss部署教程·opengauss部署文档
云水一下11 分钟前
零基础玩转bWAPP靶场(六十三):Drupal SQL Injection (Drupageddon)
sql·web安全·bwapp
旺仔学长 哈哈13 分钟前
52486|高校专业评估不再靠表格:Spring Boot 本科专业质量评估管理系统实战
数据库·spring boot·毕业设计·教育管理
梦想的旅途21 小时前
企业微信Webhook回调怎么做自动回复和AI客服
数据库·机器人·自动化·企业微信·rpa
Zguigo1 小时前
OCR 核心原理 + 模型 + 检测与识别
数据库·ocr
凤山老林1 小时前
零停机数据库演进:Spring Boot 集成 Flyway 与平滑DDL变更策略
数据库·spring boot·后端
曹牧2 小时前
Oracle:取固定分隔符字符串中第一个元素
数据库·oracle
szarron2 小时前
VNA6 便携式矢量网络分析仪:从入门到精通
数据库·嵌入式硬件·测试工具·5g·射频工程
没文化的阿浩2 小时前
【MySQL】数据类型
android·mysql·adb