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 ...
随机推荐
- XCTF练习题---MISC---give_you_flag
XCTF练习题---MISC---give_you_flag flag:flag{e7d478cf6b915f50ab1277f78502a2c5} 解题步骤: 1.观察题目,下载附件 2.打开发现是 ...
- C++实例2--职工管理系统
职工管理系统 1. 头文件 1.1 workerManager.h 系统类 1 #pragma once // 防止头文件重复包含 2 #include<iostream> // 包含输 ...
- MAC 地址为什么不需要全球唯一
MAC 地址(Media access control address)是分配给网络接口控制器(Network interface controller, NIC)的唯一标识符,它会在网络段中充当网络 ...
- 关于数据拓展及面试题讲解 Java
强类型语言 要求变量的使用严格符合规定,所有变量都必须先定义后才能使用 弱类型语言 Java 的数控类型分为两大类 基本类型(primitive type) 引用类型(reference type) ...
- QY-16 浮标水质监测站 组成 及基础参数是什么?一文认识什么是浮标水质监测站
浮标水质监测站是设立在河流.湖泊.水库.近岸海域等流 域内的现场水质自动监测实验室,是以水质监测仪为核心,运用 传感器技术,结合浮标体.电源供电系统.数据传输设备组成的 放置于水域内的小型水质监测系统 ...
- 超全面!1.5w字总结50个Java经典基础面试题(已根据知识点分类)
大家好,我是fancy. 在面试中将基础问题回答好就是成功的一半. 我总结了50道经典的Java基础面试题,里面包含面试要回答的知识重点,并且我根据知识类型进行了分类,可以说非常全面了. 小伙伴们点赞 ...
- 496. Next Greater Element I - LeetCode
Question 496. Next Greater Element I Solution 题目大意:给你一个组数A里面每个元素都不相同.再给你一个数组B,元素是A的子集,问对于B中的每个元素,在A数 ...
- 从零开始实现lmax-Disruptor队列(二)多消费者、消费者组间消费依赖原理解析
MyDisruptor V2版本介绍 在v1版本的MyDisruptor实现单生产者.单消费者功能后.按照计划,v2版本的MyDisruptor需要支持多消费者和允许设置消费者组间的依赖关系. 由于该 ...
- (1)《QT+OpenGL学习之我见》初始化窗口及三个重要函数 vs+Qt
本章前言:本章讲如何利用VS和QT来创建一个基本的QOpenGLWidget窗口和有关联的三个核心函数,因为版本更新可能会有大同小异,但基本的不会有变换,有了QT的帮助,我们不需要下载opengL.g ...
- 当JAVA注解、AOP、SpEL相遇,更多可能变为了现实
常规情况下,我们可以通过业务定制化的注解,借助AOP机制来实现某些通用的处理策略.比如定义个@Permission注解,可以用于标识在具体的方法上,然后用来指定某个方法必须要指定角色的人才能够访问调用 ...