5.SUM and COUNT

world表

name continent area population gdp
Afghanistan Asia 652230 25500100 20343000000
Albania Europe 28748 2831741 12960000000
Algeria Africa 2381741 37100000 188681000000
Andorra Europe 468 78115 3712000000
Angola Africa 1246700 20609294 100990000000
.... .... .... .... ....

  1. Show the total population of the world.
SELECT SUM(population)
FROM world;
  1. 列出所有的大陆--每个大陆只需一次。
select distinct continent from world;
  1. 给出非洲的国内生产总值总额
select sum(gdp)
 from world
where continent = 'Africa';
  1. 有多少国家的面积至少在1000000以上?
select count(name)
 from world
 where area >= 1000000;
  1. ('爱沙尼亚'、'拉脱维亚'、'立陶宛')的总人口是多少?
select sum(population)
 from world
 where name in ('Estonia', 'Latvia', 'Lithuania');
  1. 对于每个大陆,显示大陆和国家数量。
select continent, count(name)
 from world
 group by continent;
  1. 对于每个大陆,显示该大陆和人口至少为1 000万的国家数目。
select continent, count(name)
 from world
 where population >= 10000000
 group by continent;
  1. 列出总人口至少为1亿的大陆。
select continent
 from world
 group by continent
 having sum(population)>=100000000;
posted @ 2021-03-01 18:39  hj0612  阅读(78)  评论(0)    收藏  举报