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 |
| ... | ||||
SELECT SUM(population)
FROM world
2、List all the continents - just once each.
select DISTINCT(continent) from world
3、Give the total GDP of Africa
SELECT SUM(gdp)
FROM world where continent='Africa'
4、How many countries have an area of at least 1000000
select count(name) from world where area>1000000
5、What is the total population of ('France','Germany','Spain')
SELECT SUM(population)
FROM world where name in('France','Germany','Spain')
6、For each continent show the continent and number of countries.
select continent,count(name) from world group by continent
7、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、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的更多相关文章
- SQLZOO练习四--SUM and COUNT(聚合函数)
World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, ...
- SUM and COUNT -- SQLZOO
SUM and COUNT 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Show the total population of th ...
- sql中奇怪的sum(1),sum(2),count(1),count(6),count(*):统计总数
sql的统计函数 sql统计函数有 count 统计条数,配合group用 sum 累加指定字段数值 但注意sum(1)就特殊 sum(1)等同于count(*) sum(1)统计个数,功能和coun ...
- mysql练习----SUM and COUNT/zh图(二)
世界国家概况 GROUP BY 和 HAVING 通过包括一个GROUP BY子句功能, SUM并将COUNT 其应用于共享值的项目组.当你指定 GROUP BY continent 结果是每个不同的 ...
- 聚合函数:sum,count,max,avg
聚合函数:sum,count,max,avg等,一般作用于多条记录上.通过group by可以将数据对属于一组的数据起作用. SELECT region, SUM(population), SUM(a ...
- mysql sum 和 count 函数 合并使用
SELECT sum(start) as total, count(start) as rows FROM table where....
- SQL语句中SUM与COUNT的区别
SUM是对符合条件的记录的数值列求和 COUNT 是对查询中符合条件的结果(或记录)的个数 例如: 表fruit id name price 1 apple 3.00 2 ...
- sqlserver sum 和count在关于进行统计时的区别
sum是对内容的数量进行相加,count 对表行数 对象进行统计 在使用 case 时,如 select subject,count(case when score>80 then score ...
- sql - sum() 和 count() 函数的区别
对sql一直都是蜻蜓点水,突然也觉得对这两个函数的区别有点朦胧,查了一下,在这里说一下: sum():主要用于累加求和. count():主要用于行(记录)的统计.
随机推荐
- Linux命令大全----系统管理相关命令
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了Linux命令大全----系统管理相关命令,并附有实例 一.安装 ...
- 10.线程通信CountDownLatch
CountDownLatch 1.一个同步的辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个.多个线程去一直等待,用给定的计数.初始化“CountDownLatch”. 由于调用 count ...
- [Todo] Redis里面队列的两种模式,以及抢红包在Redis中的实现
两种队列模式: 一种是利用list的lpush/rpop等 另一种是redis自带的发布者/订阅者模式 http://www.cnblogs.com/alazalazalaz/p/5512258.ht ...
- jQuery/javascript实现IP/Mask自动联想功能
之前做一个云计算的项目,涉及到一个安全组自动联想的功能,思想是这样的: 安全组规则之间是可以相互引用的,也可以自己是自己手动输入的ip/mask,这时候可以加一个功能,实现securityGroupI ...
- JSP学习笔记(四):文件上传
JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图像文件或任何文档.我们使用 Servlet 来处理文件上传,使用到的文件有: upload.j ...
- ubuntu14.04如何卸载mysql
1. 删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 2. 删除mqsql的配置文件 sudo rm /etc/mysql/ -R 3. 自动卸载mysql的程序 su ...
- Android -- 再来一发Intent
之前写过一篇Intent的博客,主要说了一下隐式意图. 传送门:<Android -- Intent> Intent对象构成 Component name.Action.Data.Cate ...
- Logon database Tiger引起DataGuard不同步问题
当DataGuard升级CPU后.发现主备库不能同步了,日志报错,所以在主库的运行的升级的后脚本"@catbundle.sql cpu apply"不能同步到备库 现象: brok ...
- strcpy与strncpy
char aa[]="123456789123456789123456789"; char bb[4]={0}; 1.strcpy(bb,aa); bb的空间,不能存下aa的内容, ...
- IDEA20181.4破解
1.下载破解补丁: http://idea.lanyus.com/jar/JetbrainsIdesCrack-4.2-release-sha1-3323d5d0b82e716609808090d3d ...