sqlzoo:SUM and COUNT

梦里梦外; 2022-12-27 01:50 257阅读 0赞
  1. Show the total population of the world.
  1. SELECT SUM(population)
  2. FROM world
  1. List all the continents - just once each.
  1. SELECT continent
  2. FROM world
  3. GROUP BY continent
  4. SELECT DISTINCT continent
  5. FROM world
  1. Give the total GDP of Africa
  1. SELECT SUM(gdp)
  2. FROM world
  3. WHERE continent = 'Africa'
  1. How many countries have an area of at least 1000000
  1. SELECT COUNT(*)
  2. FROM world
  3. WHERE area >= 1000000
  1. What is the total population of (‘Estonia’, ‘Latvia’, ‘Lithuania’)
  1. SELECT SUM(population)
  2. FROM world
  3. WHERE name IN('Estonia', 'Latvia', 'Lithuania')
  1. For each continent show the continent and number of countries.
  1. SELECT continent, COUNT(*)
  2. FROM world
  3. GROUP BY continent
  1. For each continent show the continent and number of countries with populations of at least 10 million.
  1. SELECT continent, COUNT(*)
  2. FROM world
  3. where population >= 10000000
  4. GROUP BY continent
  1. List the continents that have a total population of at least 100 million.
  1. SELECT continent
  2. FROM world
  3. GROUP BY continent
  4. HAVING SUM(population) >= 100000000

发表评论

表情:
评论列表 (有 0 条评论,257人围观)

还没有评论,来说两句吧...

相关阅读