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 ...
随机推荐
- 《转载》python/人工智能/Tensorflow/自然语言处理/计算机视觉/机器学习学习资源分享
本次分享一部分python/人工智能/Tensorflow/自然语言处理/计算机视觉/机器学习的学习资源,也是一些比较基础的,如果大家有看过网易云课堂的吴恩达的入门课程,在看这些视频还是一个很不错的提 ...
- 论文解读(SAGPool)《Self-Attention Graph Pooling》
论文信息 论文标题:Self-Attention Graph Pooling论文作者:Junhyun Lee, Inyeop Lee, Jaewoo Kang论文来源:2019, ICML论文地址:d ...
- k8s入门之Secret(十)
Secret与ConfigMap都是用来存储配置信息的,不同之处在于ConfigMap是明文存储的,而Secret用来保存敏感信息,如:密码.OAuth令牌,ssh key等等.Secret常用有三种 ...
- Event Loop 是什么?
Event Loop 是什么? 本文写于 2020 年 12 月 6 日 广义上来说 Event Loop 并不是 JavaScript 独有的概念,他是一个计算机的通用概念. 狭义上来说,只有 No ...
- MongoDB是什么?非关系型数据库的优点?安装使用教程
哈喽!大家好,我是小奇,一位热爱分享的程序员 小奇打算以轻松幽默的对话方式来分享一些技术,如果你觉得通过小奇的文章学到了东西,那就给小奇一个赞吧 文章持续更新 一.前言 书接上回,由于球姐都有孩子了, ...
- 一文学会Java的交互式编程环境jshell
什么是交互式编程环境?重点词交互,在这样的编程环境中,你每输入一行代码,环境都会给你一个反馈,这就是交互式的编程环境.这种编程环境并不太适合工程化的复杂性需求,但在一些快速验证.简单计算之类的场景下还 ...
- RealEvo-IDE安装
双击"InstallWizard.exe"启动安装程序 点击"Install RealEvo-IDE"启动 RealEvo-IDE 安装程序 选择"下 ...
- python之装饰器补充与递归函数与二分查找
目录 多层装饰器 有参装饰器 递归函数 基本演示 斐波那契数列 总结 小拓展 算法之二分法 简介 举例 总结 多层装饰器 我们已经知道了语法糖的作用是将装饰对象自动装饰到装饰器中,一个语法糖的应用我们 ...
- column-文本对齐输出
文本输出对齐,可以指定对应的分隔符,将上下文的字符串按分隔符列对齐. 语法 column [选项] 选项 -s 设置分隔符,默认为空格. -t 判断输入的列数来创建一个表,使列对齐. -c 设置显示的 ...
- JAVA - error(错误)和exception(异常)有什么区别?
JAVA - error(错误)和exception(异常)有什么区别? error 表示恢复不是不可能但很困难的情况下的一种严重问题.比如说内存溢出.不可能指望程序能处理这样的情况. excepti ...