You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 04_select_within_select_tutorial.sql
+41-16
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,21 @@ WHERE population >
5
5
(
6
6
SELECT population FROM world
7
7
WHERE name='Russia'
8
+
8
9
)
9
10
10
-
-- 2. List the name and continent of countries in the continents containing
11
-
-- 'Belize', 'Belgium'.
12
-
SELECTa.name country, a.continent
13
-
FROM world a
14
-
WHEREa.continentIN
11
+
-- 2. Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.
12
+
13
+
SELECT name
14
+
FROM world
15
+
WHERE continent ='Europe'AND gdp/population>
15
16
(
16
-
SELECTb.continent
17
-
FROM world b
18
-
WHEREb.nameIN ('Belize', 'Belgium')
17
+
SELECTgdp/population
18
+
FROM world
19
+
WHERE name ='United Kingdom'
19
20
)
21
+
-- or
20
22
21
-
-- 3. Show the countries in Europe with a per capita GDP greater than
22
-
-- 'United Kingdom'.
23
23
SELECTa.name country
24
24
FROM world a
25
25
WHEREa.continent='Europe'
@@ -30,6 +30,18 @@ AND a.gdp/a.population >
30
30
WHEREb.name='United Kingdom'
31
31
)
32
32
33
+
-- 3. List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
34
+
35
+
SELECTa.name country, a.continent
36
+
FROM world a
37
+
WHEREa.continentIN (
38
+
39
+
SELECTb.continent
40
+
FROM world b
41
+
WHEREb.nameIN ('Argentina','Australia' )
42
+
)
43
+
ORDER BY country
44
+
33
45
-- 4. Which country has a population that is more than Canada but less than
34
46
-- Poland? Show the name and the population.
35
47
SELECTa.name country, a.population
@@ -47,16 +59,29 @@ AND a.population <
47
59
WHEREc.name='Poland'
48
60
)
49
61
62
+
-- 5. Germany (population 80 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.
63
+
64
+
SELECT name, CONCAT(ROUND(100*population/
65
+
(SELECT population
66
+
FROM world
67
+
WHERE name ='Germany')), '%')
68
+
FROM world
69
+
WHERE continent ='Europe'
70
+
71
+
72
+
73
+
50
74
-- 5. Which countries have a GDP greater than any country in Europe? [Give the
51
-
-- name only.]
75
+
-- name only.](Some countries may have NULL gdp values) *****THIS ONE CANT FIGURE OUT***START HERE***
52
76
SELECTa.name country
53
77
FROM world a
54
78
WHEREa.gdp> ALL
55
-
(
56
-
SELECTb.gdp
57
-
FROM world b
58
-
WHEREb.continent='Europe'
59
-
)
79
+
(
80
+
SELECTb.gdp
81
+
FROM world b
82
+
WHEREb.continent='Europe'
83
+
ANDb.population>0
84
+
)
60
85
61
86
-- 6. Find the largest country (by area) in each continent, show the continent,
0 commit comments