• 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

     

  • 相关阅读:
    为什么选择 TypeScript
    如何衡量软件系统的复杂度(三)
    LeetCode题目67:二进制求和
    第三章热备份路由选择协议(HSRP)
    RIP路由
    C++引用的知识补充
    基于electron25+vite4创建多窗口|vue3+electron25新开模态窗体
    XPS测试中CHN含量为什么测不准?-科学指南针
    零基础html学习-第五期
    软件工程概论
  • 原文地址:https://blog.csdn.net/lvcheng0309/article/details/126413684