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():主要用于行(记录)的统计.
随机推荐
- iOS: 向Github的README.md里添加图片
我们将项目上传到Github上开源供大家使用,可是,有时只是在READEME.md中做一些文字说明并不直观,如果能给上演示的截图是不是更能把功能展示的一目了然呢. 不费话了,直接上步骤: 第一步:首先 ...
- 82. Remove Duplicates from Sorted List II && i
题目 83. Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such tha ...
- 【SSH 基础】SSH框架--struts深入具体解释(一)
学习了struts,可是对于它的由来,以及为什么使用action和struts.xml的方式而不採用曾经的servlet方式.有些疑问,究竟之前的方式有什么弊端,struts又给我们带来了什么便利? ...
- component is not authorized by this account hint: [B3GVCa0189e575] 错误解决?
component is not authorized by this account hint: [aMADoA0312e514] component is not authorized by th ...
- HDU 1710 Binary Tree Traversals(二叉树)
题目地址:HDU 1710 已知二叉树先序和中序求后序. #include <stdio.h> #include <string.h> int a[1001], cnt; ty ...
- IOS开发帐号与发布问题综合
一.iOS开发:AD-HOC版应用测试方法:http://hi.baidu.com/kangle1208/item/163f39530abb4d3195eb05a7 二.plist的方式发布: 1.y ...
- span中内容随着数字长度的添加而增大
场景:导航条中数据,当数据量不大时.仅仅会显示几页,数字仅仅有1,2.3,4..,数字写在span标签中, 则span不须要多宽.设置固定宽度就能够,但当数据量很大的.比如:日志管理--有增 删 改就 ...
- javascript - return
return 使用,建议使用vsCode编译器. /** * return:中断语句运行. * * 1.return;和return false是一样的 * 2.return只能返回一个参数,可以是值 ...
- 利用html5调用本地摄像头拍照上传图片[转]
利用html5调用本地摄像头拍照上传图片 html5概念啥的就不废话了,不知道的 百度, 谷歌一堆..今天学了学html5中的Canvas结合新增的<video>标签来获取本地摄像头, ...
- Spring整合JDBC实现简单的增删改
Spring整合JDBC实现简单的增删改: 1.导入Spring的包和数据库的驱动包: 2.选择一个数据源(dbcp和C3P0) 3.导入数据源的包(这里我们使用dbcp) <span styl ...