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、Show the total population of the world.
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的更多相关文章

  1. SQLZOO练习四--SUM and COUNT(聚合函数)

    World Country Profile: Aggregate functions This tutorial is about aggregate functions such as COUNT, ...

  2. SUM and COUNT -- SQLZOO

    SUM and COUNT 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Show the total population of th ...

  3. sql中奇怪的sum(1),sum(2),count(1),count(6),count(*):统计总数

    sql的统计函数 sql统计函数有 count 统计条数,配合group用 sum 累加指定字段数值 但注意sum(1)就特殊 sum(1)等同于count(*) sum(1)统计个数,功能和coun ...

  4. mysql练习----SUM and COUNT/zh图(二)

    世界国家概况 GROUP BY 和 HAVING 通过包括一个GROUP BY子句功能, SUM并将COUNT 其应用于共享值的项目组.当你指定 GROUP BY continent 结果是每个不同的 ...

  5. 聚合函数:sum,count,max,avg

    聚合函数:sum,count,max,avg等,一般作用于多条记录上.通过group by可以将数据对属于一组的数据起作用. SELECT region, SUM(population), SUM(a ...

  6. mysql sum 和 count 函数 合并使用

    SELECT sum(start) as total, count(start) as rows FROM table where....

  7. SQL语句中SUM与COUNT的区别

    SUM是对符合条件的记录的数值列求和 COUNT 是对查询中符合条件的结果(或记录)的个数 例如: 表fruit id     name    price 1     apple     3.00 2 ...

  8. sqlserver sum 和count在关于进行统计时的区别

    sum是对内容的数量进行相加,count 对表行数 对象进行统计 在使用 case 时,如 select subject,count(case when score>80 then score ...

  9. sql - sum() 和 count() 函数的区别

    对sql一直都是蜻蜓点水,突然也觉得对这两个函数的区别有点朦胧,查了一下,在这里说一下: sum():主要用于累加求和. count():主要用于行(记录)的统计.

随机推荐

  1. lua中遍历table的几种方式比较

    当我在工作中使用lua进行开发时,发现在lua中有4种方式遍历一个table,当然,从本质上来说其实都一样,只是形式不同,这四种方式分别是: for key, value in pairs(tbtes ...

  2. combogrid 摘要

    可装载组合框 - ComboBox 继承自$.fn.combo.defaults,通过$.fn.combobox.defaults覆盖默认值 combobox显示的是一个可以编辑的文本框和一个下拉列表 ...

  3. HDU 5288 OO's sequence (2015多校第一场 二分查找)

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  4. mac活动监视器 的含义

    应用内存:应用所使用的内存数量. 联动内存:系统运行需要的内存.联动内存不能缓存且必须存放在内存中,所以不能被其他应用使用. 压缩:为腾出更多内存而压缩的内存数量.当电脑接近其最大内存能力时,内存中的 ...

  5. 阿里云服务器ajax乱码问题

    web.config增加节点      <globalization requestEncoding="utf-8" responseEncoding="utf-8 ...

  6. Ubuntu Server 13.10 安装配置图解教程

    一.Ubuntu Server 13.10系统安装 Ubuntu分为桌面版(desktop)和服务器版(Server),下面为大家介绍服务器版本Ubuntu Server 13.10的详细安装过程. ...

  7. 零基础学python-3.5 内存管理

    * 变量无需事先声明 * 变量无需指定类型 * 程序猿不用关系内存管理 * 变量名会被回收 * del能够直接释放资源 1.python使用的是引用调用,而不是值调用,他使用的回收算法是引用计数算法, ...

  8. 不同版本(2.3,2.4,2.5,3.0)的Servlet web.xml 头信息

    不同版本(2.3,2.4,2.5,3.0)的Servlet web.xml 头信息 学习了:https://blog.csdn.net/z69183787/article/details/360080 ...

  9. Linux统计/监控工具SAR详细介绍

    转载:http://www.ctohome.com/FuWuQi/1b/688.html sysstat 工具简介 sysstat 是 Linux 系统中的常用工具包.它的主要用途是观察服务负载,比如 ...

  10. Java内存溢出的详细解决方案(转http://developer.51cto.com/art/200906/129346.htm)

    一.内存溢出类型 1.java.lang.OutOfMemoryError: PermGen space JVM管理两种类型的内存,堆和非堆.堆是给开发人员用的上面说的就是,是在JVM启动时创建:非堆 ...