For each continent show the number of countries:

SELECT continent, COUNT(name)
FROM world
GROUP BY continent

For each continent show the total population:

SELECT continent, SUM(population)
FROM world
GROUP BY continent

WHERE and GROUP BY. The WHERE filter takes place before the aggregating function.

For each relevant continent show the number of countries that has a population of at least 200000000.

SELECT continent, COUNT(name)
FROM world
WHERE population>200000000
GROUP BY continent

GROUP BY and HAVING. The HAVING clause is tested after the GROUP BY. You can test the aggregated values with a HAVING clause.

Show the total population of those continents with a total population of at least half a billion.

SELECT continent, SUM(population)
FROM world
GROUP BY continent
HAVING SUM(population)>500000000

sqlzoo:using group by and having的更多相关文章

  1. 转:sql语句中GROUP BY 和 HAVING和使用 count()

    在开发时,我们经常会遇到以“累计(count)”或是“累加(sum)”为条件的查询.比如user_num表: id user num 1 a 3 2 a 4 3 b 5 4 b 7   例1:查询出现 ...

  2. sqlzoo易错题

    https://sqlzoo.net/wiki/SELECT_names 答案在:https://github.com/codyloyd/sqlzoo-solutions/blob/master/SQ ...

  3. SQLZOO 习题

    https://sqlzoo.net 8. 美國.印度和中國(USA, India, China)是人口又大,同時面積又大的國家.排除這些國家. 顯示以人口或面積為大國的國家,但不能同時兩者.顯示國家 ...

  4. More JOIN operations -- SQLZOO

    The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.List the films where the y ...

  5. The JOIN operation -- SQLZOO

    The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Modify it to show the matc ...

  6. SUM and COUNT -- SQLZOO

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

  7. SELECT within SELECT Tutorial -- SQLZOO

    SELECT within SELECT Tutorial 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.List each count ...

  8. LINQ Group By操作

    在上篇文章 .NET应用程序与数据库交互的若干问题 这篇文章中,讨论了一个计算热门商圈的问题,现在在这里扩展一下,假设我们需要从两张表中统计出热门商圈,这两张表内容如下: 上表是所有政区,商圈中的餐饮 ...

  9. Kafka消费组(consumer group)

    一直以来都想写一点关于kafka consumer的东西,特别是关于新版consumer的中文资料很少.最近Kafka社区邮件组已经在讨论是否应该正式使用新版本consumer替换老版本,笔者也觉得时 ...

随机推荐

  1. react native 中时间选择插件

    npm install react-native-datepicker --save import DatePicker from 'react-native-datepicker'; <Vie ...

  2. react native头部标题样式修改

    navigationOptions: ({navigation}) => ({ headerTitle:'评估记录', headerBackTitle:null, headerLeft:null ...

  3. 【codeforces 983E】NN country

    Description In the NN country, there are n cities, numbered from 1 to n, and n−1 roads, connecting t ...

  4. 在mysql 5.7中,创建表的字段名中包含双引号的时候,执行会报错

    解决办法,添加 SET SESSION SQL_MODE=ANSI_QUOTES;

  5. 高阶函数(Higher-order function)

    变量可以指向函数 以Python内置的求绝对值的函数abs()为例,调用该函数用以下代码: >>> abs(-15) 15 但是,如果只写abs呢? >>> abs ...

  6. winform窗体嵌套HTML页面,开发出炫彩桌面程序

    一:CEF全称Chromium Embedded Framework,是一个基于Google Chromium 的开源项目.Google Chromium项目主要是为Google Chrome应用开发 ...

  7. iOS 单选框

    iOS 单选框,可自定义横向和纵向显示,可定义显示的个数和内容,自定义间距,提供block 和代理方法可供使用,欢迎拍砖! github地址: https://github.com/joshuaGen ...

  8. 搭建企业git代码版本管理所需工具

    此片文章纯属记录一下使用gitlab搭建私有git版本管理的一些工具及概念. 先记录一下概念 git         是一种版本控制系统,是一个命令,是一种工具 github   是一个基于git实现 ...

  9. MQTT控制---pingreq

    心跳请求 客户端向服务端发送PINGREQ报文用于: 在没有任何其他控制报文从client发给server时,告诉server,client还活着 请求server发送 响应确认它还活着 使用网络以确 ...

  10. spring5.0.2.RELEASE源码环境构建

    Spring5 源码下载注意事项 首先你的JDK 需要升级到1.8 以上.Spring3.0 开始,Spring 源码采用github 托管,不再提供官网下载链接.大家可自行去github 网站下载, ...