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. Jacob调用COM组件总结,实例

    转自:http://blog.csdn.net/whw6_faye/article/details/5418506 最近做了一个Java Jacob调用COM组件的东西,其中遇到了不少问题,现在把经验 ...

  2. MFC HTML的img显示摄像头图像

    cv::VideoCapture vc; vc.open(0); cv::Mat temp; vc.read(temp); //cv::resize(temp,temp,cv::Size(320,24 ...

  3. jQuery EasyUI 数据网格 - 条件设置行背景颜色

    $('#tt').datagrid({ rowStyler:function(index,row){ if (row.listprice>50){ return 'color:blue;font ...

  4. Django文档学习

    文档位置:https://docs.djangoproject.com/zh-hans/2.1/

  5. Nginx发展现状及未来特性

    Nginx ("engine x")是一个高性能的HTTP和反向代理 服务器,也是一个IMAP/POP3/SMTP 代理服务器,其特点是占用内存少,并发能力强.到目前完为止,Ngi ...

  6. nmap速查表v1.0

    基本语法: #nmap [扫描方式] [命令选项] {目标}   扫描目标格式: IPv4 地址: 192.168.1.1IPv6 地址:AABB:CCDD::FF%eth0主机名:www.targe ...

  7. js 小数点 取整数

    取整数 Math.round() 小数点 (10/3).toFixed(2)

  8. 20个初学者实用的CSS技巧

    过去就连一个镜像站点,我们都依靠大量的开发人员和程序员进行维护.得益于CSS和它的灵活性使得样式能够从代码中被独立抽离出来,从而让一个只具备基本CSS理论的初学者都能够轻易地改变网站的样式. 不论你是 ...

  9. SWFUpload 已上传成功数量控制 插件(用于解决队列满问题)

    当我们在使用 SWFUpload 做文件上传时,我们需要把已经上传的文件列表做一个删除, 但在我们把已上传列表删除后,再重新上传时,会发现提示 上传队列满 的问题,原因就是有一个状态对象中的一个 成功 ...

  10. MS SQL 中判断 数据库, 存储过程,表,临时表,视图,函数,用户,用户创建对象 等是否存在 SQL脚本

    摘自: http://www.111cn.net/database/mssqlserver/39107.htm sql判断存储过程是否存在 判断数据库教程是否存在 Sql代码 if exists (s ...