-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01. Select within Select
48 lines (41 loc) · 1.39 KB
/
01. Select within Select
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--01. Bigger than Russia.
SELECT name FROM world
WHERE population >
(SELECT population FROM world
WHERE name='Russia');
--02. Richer than UK
SELECT name FROM world
WHERE continent = 'Europe'
AND gdp / population > (SELECT gdp / population FROM world WHERE name = 'United Kingdom');
/*03. Neighbours of Argentina and Australia*/
SELECT name,continent
FROM world
WHERE
continent IN (SELECT continent FROM world
WHERE name IN ('Australia','Argentina'))
ORDER BY name;
/*04. Between Canada and Poland*/
SELECT name,population
FROM world
WHERE population >(
SELECT population FROM world WHERE name = 'Canada')
AND population <(
SELECT population FROM world WHERE name = 'Poland');
--05. Percentages of Germany
SELECT name,
CONCAT (ROUND(population /(SELECT population
FROM world WHERE name = 'Germany') * 100,0),'%') AS population
FROM world WHERE continent = 'Europe';
--06. Bigger than every country in Europe
SELECT name FROM world
WHERE gdp > ALL (SELECT gdp FROM world WHERE continent = 'Europe' AND gdp > 0);
--07. Largest in each continent
SELECT continent, name, area FROM world x
WHERE area >= ALL
(SELECT area FROM world y
WHERE y.continent=x.continent);
--08. First country of each continent (alphabetically)
SELECT continent,name FROM world x
WHERE name <= ALL
(SELECT name FROM world y WHERE x.continent = y.continent)
ORDER BY name;