当前位置:   article > 正文

SQLZOO——5 SUM and COUNT_show the total population of the world. world(name

show the total population of the world. world(name, continent, area, populat

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.

Total world population


1.

Show the total population of the world.

world(name, continent, area, population, gdp)
  1. SELECT SUM(population)
  2. FROM world

 

List of continents


2.

List all the continents - just once each.

  1. select distinct continent
  2. from world

 

GDP of Africa


3.

Give the total GDP of Africa

  1. select sum(gdp)
  2. from world
  3. where continent = 'Africa'

Count the big countries


4.

How many countries have an area of at least 1000000

  1. select count(name)
  2. from world
  3. where area >= 1000000

  

Baltic states population


5.

What is the total population of ('Estonia', 'Latvia', 'Lithuania')

  1. select sum(population)
  2. from world
  3. where name in ('Estonia', 'Latvia', 'Lithuania')

Counting the countries of each continent


6.

For each continent show the continent and number of countries.

  1. select continent,count(name)
  2. from world
  3. group by continent

Counting big countries in each continent


 7.

For each continent show the continent and number of countries with populations of at least 10 million.

  1. select continent,count(name)
  2. from world
  3. where population > 10000000
  4. group by continent

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号