• SQLZOO——SELECT within SELECT Tutorial


    Bigger than Russia


    1.

    List each country name where the population is larger than that of 'Russia'.

    world(name, continent, area, population, gdp)
    1. SELECT name
    2. FROM world
    3. WHERE population >
    4. ( SELECT population
    5. FROM world
    6. WHERE name='Russia')

    Richer than UK


    2.

    Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.

    Per Capita GDP

    The per capita GDP is the gdp/population

    1. select name
    2. from world
    3. where continent = 'Europe' and gdp/population >
    4. ( select gdp/population
    5. from world
    6. where name = 'United Kingdom')

    Neighbours of Argentina and Australia


    3.

    List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.

    1. select name,continent
    2. from world
    3. where continent in
    4. ( select continent
    5. from world
    6. where name in ('Argentina','Australia'))
    7. order by name

    Between Canada and Poland


    4.

    Which country has a population that is more than United Kingom but less than Germany? Show the name and the population.

    1. select name,population
    2. from world
    3. where population >
    4. ( select population
    5. from world
    6. where name = 'United Kingdom')
    7. and population <
    8. ( select population
    9. from world
    10. where name = 'Germany')

    Percentages of Germany


    5.

    Germany (population 80 million) has the largest population of the countries in Europe. Austria (population 8.5 million) has 11% of the population of Germany.

    Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.

    The format should be Name, Percentage for example:

    1. select name,concat(cast(round(100*population/(select population from world where name='Germany'),0) as int),'%')
    2. from world
    3. where continent='Europe'

     注意:

    cast 函数:类型转换;concat 函数:字符串拼接;round函数:四舍五入

    Bigger than every country in Europe


    6.

    Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)

    1. select name
    2. from world
    3. where gdp > all
    4. (select gdp
    5. from world
    6. where gdp is not null and continent = 'Europe')

    Largest in each continent


    7.

    Find the largest country (by area) in each continent, show the continent, the name and the area:

    1. SELECT continent, name, area
    2. FROM world x
    3. WHERE area>= ALL
    4. (SELECT area
    5. FROM world y
    6. WHERE y.continent = x.continent AND area>0)

    First country of each continent (alphabetically)


    8.

    List each continent and the name of the country that comes first alphabetically.

    1. select continent, name
    2. from world a where name <= all
    3. (select name from world b where a.continent = b.continent)

    Difficult Questions That Utilize Techniques Not Covered In Prior Sections


    9.

    Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show namecontinent and population.

    1. select name,continent,population
    2. from world a
    3. where 25000000 >= all
    4. (select population
    5. from world b
    6. where a.continent = b.continent)

    Three time bigger


    10.

    Some countries have populations more than three times that of all of their neighbours (in the same continent). Give the countries and continents. 

    1. select name,continent
    2. from world a
    3. where a.population/3 >= all
    4. (select population
    5. from world b
    6. where a.continent = b.continent and a.name != b.name)

  • 相关阅读:
    CentOS8安装RabbitMQ
    Java里面int、Integer、String相互转换
    Lesson 1 A private conversation
    FPGA实现UDP传输视频,提供2套verilog工程源码和接收显示上位机程序
    招聘全球视野:跨境电商的人才策略
    bit band
    记第二次线上问题排查过程
    git reset 和 git revert的使用
    vue-cli项目因为webpack版本不兼容运行后报错
    使用mybatis编写Mapper.xml配置文件的时候,sql自动提示不显示且表爆红
  • 原文地址:https://blog.csdn.net/lvcheng0309/article/details/125961524