From 821a18ea38655fc8f513e724ddc8ecca816a9eb2 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Thu, 2 May 2019 17:28:58 +0800 Subject: [PATCH] Solution for 10th question in SELECT within SELECT --- 4_soutions.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/4_soutions.sql b/4_soutions.sql index 2d1cec0..8d31485 100644 --- a/4_soutions.sql +++ b/4_soutions.sql @@ -47,3 +47,13 @@ GROUP BY continent HAVING max(population) <= 25000000) AS x ON y.continent = x.continent +--10. Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents. +SELECT name, continent +FROM world w1 +WHERE population >= + ALL( + SELECT population * 3 FROM world w2 + WHERE w1.continent = w2.continent + AND w1.name <> w2.name + ) +