SQLZOO练习四--SUM and COUNT(聚合函数)
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.
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、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;
SQLZOO练习四--SUM and COUNT(聚合函数)的更多相关文章
- count()聚合函数正确用法
count()聚合计算 count()是聚合函数,对于返回的结果集,一行行地判断,累计值加1,最后返回累计值,count(*).count(主键ID)和count(1)表示返回满足条件的结果集的总行数 ...
- mysql/mariadb学习记录——查询3(AVG、SUM、COUNT)函数
AVG() 求平均数函数: //求emp表中的sal属性的平均值 mysql> select avg(sal) as salAverage from emp; +-------------+ | ...
- sqlzoo练习答案--SUM and COUNT
World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, ...
- Django ORM 多对多操作 使用聚合函数和分组 F查询与Q查询
创建表 # models.py form django.db import models class Book(models.Model): # 表名book,django会自动使用项目名+我们定义的 ...
- MDX Step by Step 读书笔记(七) - Performing Aggregation 聚合函数之 Sum, Aggregate, Avg
开篇介绍 SSAS 分析服务中记录了大量的聚合值,这些聚合值在 Cube 中实际上指的就是度量值.一个给定的度量值可能聚合了来自事实表中上千上万甚至百万条数据,因此在设计阶段我们所能看到的度量实际上就 ...
- sqlserver的over开窗函数(与排名函数或聚合函数一起使用)
首先初始化表和数据 create table t_student( Id INT, Name varchar(), Score int, ClassId INT ); insert i ...
- 第08章 MySQL聚合函数
第08章 MySQL聚合函数 我们上一章讲到了 SQL 单行函数.实际上 SQL 函数还有一类,叫做聚合(或聚集.分组)函数,它是对一组数据进行汇总的函数,输入的是一组数据的集合,输出的是单个值. 1 ...
- TSQL 聚合函数忽略NULL值
max,min,sum,avg聚合函数会忽略null值,但不代表聚合函数不返回null值,如果表为空表,或聚合列都是null,则返回null.count 聚合函数忽略null值,如果聚合列都是null ...
- 一.oracle的SQL中group by使用的情况(与聚合函数的关系)
SELECT r.industry_1,r.industry_2,r.agent_id,r.agent_name,COUNT(DISTINCT r.customer_name_a)数据总量,COUNT ...
随机推荐
- bellman-ford 单源最短路问题 图解
核心思想:松弛操作 对于边(u,v),用dist(u)和(u,v)的和尝试更新dist(v): dist(v) = min(dist(v) , dist(u)+l(u,v) 注:dist(i)为源 ...
- [AcWing 51] 数字排列
点击查看代码 class Solution { public: vector<vector<int>> res; vector<vector<int>> ...
- [笔记] 轮廓线 DP
是状态 DP 的一种,主要是对于网格图状压,实现 \(O(1)\) 转移的一种处理方式. oooo---- ----x - 是状压了信息的位置,x 是当前更新的位置. 应用价值 可以一格一格考虑状态, ...
- 干货 | 手把手教你搭建一套OpenStack云平台
1 前言 今天我们为一位朋友搭建一套OpenStack云平台. 我们使用Kolla部署stein版本的OpenStack云平台. kolla是用于自动化部署OpenStack的一个项目,它基于dock ...
- 浅谈 UNIX、Linux、ios、android 他们之间的关系
开源Linux 一个执着于技术的公众号 Unix, 简化形成了Linux,Linux则是Android的内核,而苹果则是使用unix系统作为ios和macos的内核. 几个系统出现的时间 UNIX系统 ...
- 异步加载数据——turn.js
var tostore = GetQueryString("tostore"); var photo_id = GetQueryString("photo_id" ...
- ansible的roles使用
1.创建roles文件夹 mkdir roles 2.在roles文件夹里面创建文件夹 cd roles/ mkdir {nginx,uwsgi,redis,mysql} 3.cd nginx 4.m ...
- ifconfig出现bash: ifconfig:command not found解决办法之解决连环问题
Centos7中没有安装ifconfig命令的解决方法 在这之前,centos7最小化安装默认是不能联网的,首先必须切换到root用户,再解决网络问题 一. 切换到root用户 二. ...
- Svelte3.x网页聊天实例|svelte.js仿微信PC版聊天svelte-webchat
基于Svelte3+SvelteKit+Sass仿微信Mac界面聊天实战项目SvelteWebChat. 基于svelte3+svelteKit+sass+mescroll.js+svelte-lay ...
- python文件操作拓展与认识函数
目录 文件内光标的移动(了解即可) 前言 控制光标移动seek()方法 文件的修改 函数 语法结构 简单的使用 作业 答案 文件内光标的移动(了解即可) 前言 在文件的内置方法中,read()方法是可 ...