Sqlzoo practice Answer--select within SELECT Tutorial

Source: Internet
Author: User





This tutorial looks at how we can use the SELECT statements within SELECT statements to perform more complex queries.



Area
name Continent population GDP
asia 652230 25500100 20343000000
albania europe 28748 2831741 12960000000
algeria africa 2381741 37100000 188681000000
andorra europe 468 3712000000
Angola Africa 1246700 20609294 100990000000
...


1.


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



World (name, continent, area, population, GDP)

SELECT name FROM world
  WHERE population >
     (SELECT population FROM world
      WHERE name=‘Russia‘)


2.Show The countries in Europe with a per capita GDP greater than ' for Kingdom '.
SELECT name FROM world
  WHERE gdp/population >
     (SELECT gdp/population FROM world
      WHERE name=‘United Kingdom‘) and continent=‘Europe‘


3.List thename andContinentof countries in the continents containing eitherArgentinaorAustralia. Order by name of the country.
select name,population from world where population > (select population from world where name=‘Canada‘) and population <(select population from world where name=‘Poland‘) order by name


4.which country have a population that's more than Canada but less than Poland? Show the name and the population.
Select Name,population from world where population > (select population from world where name= ' Canada ') and population < (select population from world where name= ' Poland ') Order by name


5.


Germany (population 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.



Decimal placespercent Symbol%
Select Name,concat (ROUND (100*population/(select population from world where name= ' Germany ')), '% ') from the world where Continent= ' Europe '



6.which countries has a GDP greater than every country in Europe? [Give thenameOnly .] (Some countries may has NULL GDP values)
Select name from world where GDP > all (select GDP from world where GDP > 0 and continent= ' Europe ')



7.Find the largest country in each continent, show theContinent, thename and the Area:
SELECT continent, name, area FROM world x
  WHERE x.area >=
    ALL(SELECT y.area FROM world y
        WHERE y.continent=x.continent
          AND area>0)


8.List each continent and the name of the country, that comes first alphabetically.
Select Continent,name from World x where X.name= (select Y.name from World y where y.continent=x.continent order by name Li MIT 1)



9.Find The continents where all countries has a population <= 25000000. Then find the names of the countries associated with these continents. Showname, Continent andpopulation.
SELECT name, continent, population FROM world x
  WHERE 25000000>=ALL (SELECT population FROM world y
                         WHERE x.continent=y.continent
                         AND population>0)



< Span style= "Color:rgb (37, 37, 37); Font-family:sans-serif; font-size:14px; line-height:22.4px; " > 10, Some countries has populations more than three times, that's any of the their neighbours (in the same continent). Give the countries and continents.
Select Name,continent from World x where X.POPULATION/3 >= all (select population from World y where x.continent=y.conti Nent and X.name!=y.name and y.population>0)





Sqlzoo practice Answer--select within SELECT Tutorial




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.