zoukankan      html  css  js  c++  java
  • mysql----Nested SELECT Quiz

     

     Nested SELECT quiz
    bbc
    nameregionareapopulationgdp
    Afghanistan South Asia 652225 26000000  
    Albania Europe 28728 3200000 6656000000
    Algeria Middle East 2400000 32900000 75012000000
    Andorra Europe 468 64000  
    Bangladesh South Asia 143998 152600000 67144000000
    United Kingdom Europe 242514 59600000 2022824000000
    ...
    1. Select the code that shows the name, region and population of the smallest country in each region
     SELECT region, name, FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
    
     SELECT region, name, population FROM bbc WHERE population <= ALL (SELECT population FROM bbc WHERE population>0)
    
     SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
    
     SELECT region, name, population FROM bbc x WHERE population = ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
    
     SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population<0)
    
    2. Select the code that shows the countries belonging to regions with all populations over 50000
     SELECT name,region,population FROM bbc x WHERE 50000 < ALL (SELECT population FROM bbc y WHERE population>0)
    
     SELECT name,region,population FROM bbc x WHERE 50000 < ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
    
     SELECT name,region,population FROM bbc x WHERE 50000 = ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
    
     SELECT name,region,population FROM bbc x WHERE 50000 > ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
    
     SELECT name,region,population FROM bbc x WHERE 500000 < ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
    
    3. Select the code that shows the countries with a less than a third of the population of the countries around it
    SELECT name, region FROM bbc x
     WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
    
    SELECT name, region FROM bbc x
     WHERE population = ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
    
    SELECT name, region FROM bbc x
     WHERE population > ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
    
     SELECT name, region FROM bbc x WHERE population < ALL (SELECT population*3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
    
     SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.name != x.name)
    
    4. Select the result that would be obtained from the following code:
    SELECT name FROM bbc
     WHERE population >
           (SELECT population
              FROM bbc
             WHERE name='United Kingdom')
       AND region IN
           (SELECT region
              FROM bbc
             WHERE name = 'United Kingdom')
    
    Table-A
    Andorra
    Albania
    Austria
    Bulgaria
    Table-B
    France Europe
    Germany Europe
    Russia Europe
    Turkey Europe
    Table-C
    France
    Germany
    Andorra
    Albania
    Table-D
    France
    Germany
    Russia
    Turkey
    Table-E
    France
    Germany
    Russia
    Turkey
    Brazil
    United States of USA
    Canada
    5. Select the code that would show the countries with a greater GDP than any country in Africa (some countries may have NULL gdp values).
    SELECT name FROM bbc
     WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp=0)
    
    SELECT name FROM bbc
     WHERE gdp > (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa')
    
    SELECT name FROM bbc
     WHERE gdp > ALL (SELECT MIN(gdp) FROM bbc WHERE region = 'Africa')
    
    SELECT name FROM bbc
     WHERE gdp > ALL (SELECT gdp FROM bbc WHERE region = 'Africa')
    
    SELECT name FROM bbc
     WHERE gdp > ALL (SELECT gdp FROM bbc WHERE region = 'Africa' AND gdp<>NULL)
    
    6. Select the code that shows the countries with population smaller than Russia but bigger than Denmark
    SELECT name FROM bbc
     WHERE population < (SELECT population FROM bbc WHERE name='Denmark')
       AND population > (SELECT population FROM bbc WHERE name='Russia')
    
    SELECT name FROM bbc
     WHERE population < (SELECT population FROM bbc WHERE name='Russia')
       AND population > (SELECT population FROM bbc WHERE name='Denmark')
    
    SELECT name FROM bbc
     WHERE population = (SELECT population FROM bbc WHERE name='Russia')
       AND population > (SELECT population FROM bbc WHERE name='Denmark')
    
    SELECT name FROM bbc
     WHERE population > (SELECT population FROM bbc WHERE name='Russia')
       AND population > (SELECT population FROM bbc WHERE name='Denmark')
    
    SELECT name FROM bbc
     WHERE population < (SELECT population FROM bbc WHERE name='Russia'
       AND population > (SELECT population FROM bbc WHERE name='Denmark')
    
    7. >Select the result that would be obtained from the following code:
    SELECT name FROM bbc
     WHERE population > ALL
           (SELECT MAX(population)
              FROM bbc
             WHERE region = 'Europe')
       AND region = 'South Asia'
    
    Table-A
    Afghanistan
    Bhutan
    Nepal
    Sri Lanka
    The Maldives
    Table-B
    Bangladesh
    India
    Pakistan
    Table-C
    China
    India
    Table-D
    Brazil
    Bangladesh
    China
    India
    Table-E
    France
    Germany
    Russia
    Trukey
  • 相关阅读:
    多网卡绑定
    deepin 20.2.3 数字时钟屏保
    (原创)odoo15(master)下,列表导出权限控制
    在CentOS7上扩容centos-root根目录
    Linux扩容-新增磁盘分区挂载-fdisk
    Docker
    隐私政策(URL)
    快排代码
    反射将对象所有属性(含集合中所有属性)中字符串类型做trim()
    Prometheus 查询语句
  • 原文地址:https://www.cnblogs.com/tk55/p/6755229.html
Copyright © 2011-2022 走看看