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 ...
随机推荐
- “如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
"如何实现集中管理.灵活高效的CI/CD"在线研讨会精彩片段分享 片段主讲人:李培(西瓜刀) 大家好,我是李培.前面听文老师讲DevOps,包括CI/CD 的一些理论,也是挺有 ...
- 使用fastai训练的一个性别识别模型
在学习了python中的一些机器学习的相关模块后,再一次开始了深度学习之旅.不过与上次的TensorFlow框架不同,这一次接触的是fast.ai这样一个东西.这个框架还不稳定,网上也没有相关的中文文 ...
- 论文解读(DAGNN)《Towards Deeper Graph Neural Networks》
论文信息 论文标题:Towards Deeper Graph Neural Networks论文作者:Meng Liu, Hongyang Gao, Shuiwang Ji论文来源:2020, KDD ...
- SpringJDBC和事务控制
SpringJDBC和事务控制 主要内容 1.基本配置 <!--依赖导入--> <dependencies> <!-- 添加相关的依赖坐标 --> <!-- ...
- ONNX Runtime 源码阅读:Graph::SetGraphInputsOutputs() 函数
目录 前言 正文 总结 前言 为了深入理解ONNX Runtime的底层机制,本文将对 Graph::SetGraphInputsOutputs() 的代码逐行分析. 正文 首先判断Graph是否从O ...
- 【FineBI】FineBI连接阿里云mysql教程
因为某些原因需要查看数据信息,之前连接成功一次,今天软件更新了以后发现连接信息丢. 又重新折腾了一下. 主要有2个地方: 1.查看阿里云数据库外网连接地址:打开云数据库RDS-实例列表-管理-数据库连 ...
- 第30章 LeetCode 72 编辑距离
每日一句 A flower cannot blossom without sunshine, and man cannot live without love. 花没有阳光就不能盛开,人没有爱就不能生 ...
- vuex+Es6语法补充-Promise
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式,采用 集中式存储管理 单页面的状态管理/多页面状态管理 使用步骤: // 1.导入 import Vuex from 'vuex' // ...
- 一分钟学会如何自定义小程序轮播图(蜜雪冰城Demo)
最近开发小程序项目用到了轮播图,默认的有点单调,作为后端程序员,研究一番最终实现了.本文会从思路,代码详细介绍,相信读过此文后,不管以后在开发中碰到轮播图还是需要自定义修改其他的样式都可以按这个思路解 ...
- Navicat 连接 MySQL
目录 简述 新建连接 常见错误 简述 Navicat 是一套快速.可靠和全面的数据库管理工具,专门用于简化数据库管理和降低管理成本.Navicat 图形界面直观,提供简便的管理方法,设计和操作 MyS ...