ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

vSQLZOO练习四--SUM and COUNT(聚合函数)

2022-05-13 12:32:02  阅读:197  来源: 互联网

标签:COUNT vSQLZOO countries -- each world continent select population


World Country Profile: Aggregate functions

This tutorial is about aggregate functions such as COUNT, SUM and AVG. An aggregate function takes many values and delivers just one value. For example the function SUM would aggregate the values 2, 4 and 5 to deliver the single value 11.

namecontinentareapopulationgdp
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、Total world population

获取总人口。

Show the total population of the world.

SELECT SUM(population)
FROM world;

2、Lists of continent

List all the continents - just once each.

select DISTINCT(continent)
from world;

解题思路:distinct去重

3、GDP of Africa

获取非洲的gdp。

Give the total GDP of Africa

select sum(gdp)
from world
where continent='Africa';

4、count the big countries

计算有多少个国家,面积大于1000000

How many countries have an area of at least 1000000

select count(name)
from world
where area >=1000000;

5、Baltic states population

获取'Estonia', 'Latvia', 'Lithuania'的总人口。

What is the total population of ('Estonia', 'Latvia', 'Lithuania')

SELECT SUM(population)
FROM world
WHERE name IN('Estonia','Latvia','Lithuania');

6、Counting the countries of each continent

根据大洲分组,获取每个大洲还有国家的数量。

For each continent show the continent and number of countries.

select continent,count(name)
from world
group by continent;

7、Counting big countries in each continent

根据大洲分组,获取人口超过1000万的大洲名称,以及国家数量。

For each continent show the continent and number of countries with populations of at least 10 million.

select continent,count(name)
from world
where population>=10000000
group by continent;

8、counting big countries

获取总人口超过1亿的大洲名称。

List the continents that have a total population of at least 100 million.

select continent
from world
group by continent
having sum(population)>=100000000;

标签:COUNT,vSQLZOO,countries,--,each,world,continent,select,population
来源: https://www.cnblogs.com/ruoli-121288/p/16266268.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有