본문 바로가기
MySQL

sqlzoo.net 답 (SELECT within select tutorial)

https://sqlzoo.net/wiki/SELECT_within_SELECT_Tutorial

 

SELECT within SELECT Tutorial - SQLZOO

This tutorial looks at how we can use SELECT statements within SELECT statements to perform more complex queries. namecontinentarea populationgdp AfghanistanAsia6522302550010020343000000 AlbaniaEurope28748 2831741 12960000000 AlgeriaAfrica2381741 37100000

sqlzoo.net

SELECT within select tutorial

--no1

select name from world
where population > (select population from world
where name='Russia')

 

--no2

select name
from world
where continent='Europe' and (gdp/population) >
(select gdp/population from world
where name='United Kingdom')


--no3

select name, continent
from world
where
continent = (select continent from world where name='Argentina')
or
continent = (select continent from world where name='Australia')
order by name;
SELECT name, continent
FROM world
WHERE continent IN (SELECT continent FROM world WHERE name IN ('Argentina', 'Australia'))
ORDER BY name


--no4

select name, population from world
where
population >
(select population from world where name = 'Canada')
and
population <
(select population from world where name = 'Poland')


--no5

select name, concat(ROUND((population/
(select population from world where name = 'Germany'))*100,0),'%')
as Percentage
from world where continent = 'Europe';

 

--no6

select name from world
where
gdp > all
(select gdp from world where gdp > 0 and continent='Europe');


--no7

SELECT continent, name, area
FROM world x
WHERE area >= ALL
(SELECT area FROM world y WHERE y.continent=x.continent AND area>0)


--no8

SELECT continent, name
FROM world x
WHERE name <= ALL(SELECT name FROM world y WHERE y.continent = x.continent)


--no9

select
name, continent, population
from world x
where 25000000 >=
all(select population from world y
where x.continent = y.continent and population > 0)


--no10

SELECT name, continent
FROM world x
WHERE population > 
ALL(SELECT population*3 FROM world y 
WHERE x.continent = y.continent AND population > 0 AND y.name != x.name)