5 SUM and COUNT

练习来自网站:http://sqlzoo.net/wiki/SUM_and_COUNT

image.png

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 ('Estonia', 'Latvia', 'Lithuania')

SELECT SUM(population) 
FROM world
WHERE name IN ('Estonia', 'Latvia', 'Lithuania')

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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,178评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,500评论 0 23
  • 很多人听到微商这个职业,第一反应是杀熟,从熟人生意开始,到结束的一个坑人模式,其次,所理解的工作模式,就是发发朋友...
    小光1阅读 3,465评论 0 0
  • 我来自远方 你是到海边去 山上的溪流来了 涌进大海
    泛夜孤舟阅读 1,531评论 0 1
  • 那是一个细雨蒙蒙的夜晚,我家迎来了一位新的朋友,是我最喜欢的一种动物‘小狗’。 ...
    梦里的春天阅读 1,679评论 0 1

友情链接更多精彩内容