-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNested_Select_Quiz.sql
112 lines (106 loc) · 2.13 KB
/
Nested_Select_Quiz.sql
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- Nested SELECT Quiz
-- 1) Code that shows the name, region and population of the smallest country in each region
SELECT
region, name, population
FROM
bbc x
WHERE
population <= ALL (SELECT
population
FROM
bbc y
WHERE
y.region = x.region AND population > 0);
-- 2) 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
x.region = y.region AND y.population > 0);
-- 3) 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);
-- 4) 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');
-- Ans:
-- France
-- Germany
-- Russia
-- Turkey
SELECT
name
FROM
bbc
WHERE
gdp > (SELECT
MAX(gdp)
FROM
bbc
WHERE
region = 'Africa');
-- 6) 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 = 'Russia')
AND population > (SELECT
population
FROM
bbc
WHERE
name = 'Denmark');
-- 7) 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';
-- Ans:
-- Bangladesh
-- India
-- Pakistan