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():主要用于行(记录)的统计.
随机推荐
- 优化png图片的历程
一.使用yslow一个tool 找到一个叫做smush的工具,点击就可以进入工具的页面. 然后你就能够压缩,下载压缩后的图片. 可是终于我还是没有选择这个方案.由于压缩的图片大小还是太大了,我认为还 ...
- git 使用详解-- tag打标签
Git 的标签管理.跟大多数的 VCS 工具一样,git 也有在历史状态的关键点“贴标签”的功能,一般人们用这个功能来标记发布点(例如’v1.0′). 列出git中现有标签 要想列出git中现有的所有 ...
- Windows MongoDB安装配置
1.下载 官网:http://www.runoob.com/mongodb/mongodb-window-install.html 由于是在window下,所以我下载的是mongodb-win32-x ...
- Woocommerce 分类下的产品如何使用ID号来作为默认排序字段
在给一个客户开发网店系统时使用了WordPress系统的Woocommerce插件 WordPress版本:3.8 Woocommerce版本:2.0.20 如果没有指定排序规则(指定的字段),则Wo ...
- Android反编译方法(class+xml)
ps:对于软件开发人员来说,保护代码安全也是比较重要的因素之一,不过目前来说Google Android平台选择了Java Dalvik VM的方式使其程序很容易破解和被修改,首先APK文件其实就是一 ...
- UNIX网络编程读书笔记:原始套接口
概述 应用程序可以绕过传输层而直接使用IPv4和IPv6,这称为原始套接口(raw socket).http://www.cnblogs.com/nufangrensheng/p/3583435.ht ...
- springmvc 入门(1)
1.1 Springmvc 本套课程基于spring4.X来讲解的 SpringMVC 概述 Spring 为展现层提供的基于 MVC 设计理念的优秀的 Web 框架,是目前最主流的 MVC 框架之一 ...
- SqlServer字段说明查询及快速查看表结构
SqlServer字段说明查询 SELECT t.[name] AS 表名,c.[name] AS 字段名,cast(ep.[value] )) AS [字段说明] FROM sys.tables A ...
- unix 网络编程 第七章
1 getsockopt和setsockopt函数 套接字选项粗分为两大基本类型:一是启用或禁止某个特性的二元选项,二是取得并返回特定值的选项,参数都是以指针形式传入的. 2 套接字状 ...
- javascript 面向对象编程(工厂模式、构造函数模式、原型模式)
javascript 面向对象编程(工厂模式.构造函数模式.原型模式) CreateTime--2018年3月29日17:09:38 Author:Marydon 一.工厂模式 /** * 工厂模 ...