• SQLZOO——5 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.

    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

     

  • 相关阅读:
    DGIOT数字工厂工单结构介绍
    cmake 教程
    【LeetCode】2.两数相加
    基于Proteus平台的TEC-5H模型计算机电路设计与仿真
    Vue项目路由加前缀
    球谐函数原理
    手机如何投屏到电脑
    LeetCode刷题第2周小结
    Open3D 进阶(18)整体最小二乘拟合平面
    【Python 零基础入门】 Numpy
  • 原文地址:https://blog.csdn.net/lvcheng0309/article/details/126413684