Skip to content

Commit c90eeea

Browse files
answers on lesson 04 up to edsfocci#5, got stuck on 5
1 parent f8ce4e8 commit c90eeea

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

04_select_within_select_tutorial.sql

+41-16
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ WHERE population >
55
(
66
SELECT population FROM world
77
WHERE name='Russia'
8+
89
)
910

10-
-- 2. List the name and continent of countries in the continents containing
11-
-- 'Belize', 'Belgium'.
12-
SELECT a.name country, a.continent
13-
FROM world a
14-
WHERE a.continent IN
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>
1516
(
16-
SELECT b.continent
17-
FROM world b
18-
WHERE b.name IN ('Belize', 'Belgium')
17+
SELECT gdp/population
18+
FROM world
19+
WHERE name = 'United Kingdom'
1920
)
21+
-- or
2022

21-
-- 3. Show the countries in Europe with a per capita GDP greater than
22-
-- 'United Kingdom'.
2323
SELECT a.name country
2424
FROM world a
2525
WHERE a.continent = 'Europe'
@@ -30,6 +30,18 @@ AND a.gdp/a.population >
3030
WHERE b.name = 'United Kingdom'
3131
)
3232

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+
SELECT a.name country, a.continent
36+
FROM world a
37+
WHERE a.continent IN (
38+
39+
SELECT b.continent
40+
FROM world b
41+
WHERE b.name IN ('Argentina','Australia' )
42+
)
43+
ORDER BY country
44+
3345
-- 4. Which country has a population that is more than Canada but less than
3446
-- Poland? Show the name and the population.
3547
SELECT a.name country, a.population
@@ -47,16 +59,29 @@ AND a.population <
4759
WHERE c.name = 'Poland'
4860
)
4961

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+
5074
-- 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***
5276
SELECT a.name country
5377
FROM world a
5478
WHERE a.gdp > ALL
55-
(
56-
SELECT b.gdp
57-
FROM world b
58-
WHERE b.continent = 'Europe'
59-
)
79+
(
80+
SELECT b.gdp
81+
FROM world b
82+
WHERE b.continent = 'Europe'
83+
AND b.population>0
84+
)
6085

6186
-- 6. Find the largest country (by area) in each continent, show the continent,
6287
-- the name and the area:

0 commit comments

Comments
 (0)