From b0665e127bdb37e2204c69a4ca84ab1145234b77 Mon Sep 17 00:00:00 2001 From: Imran Imtiaz Date: Tue, 2 Jul 2024 10:16:12 +0400 Subject: [PATCH] Optimize SQL query to select countries with GDP exceeding Europe's maximum --- sqlzoo/BiggerThanEurope.sql | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sqlzoo/BiggerThanEurope.sql b/sqlzoo/BiggerThanEurope.sql index bb32f52..cc6cda5 100644 --- a/sqlzoo/BiggerThanEurope.sql +++ b/sqlzoo/BiggerThanEurope.sql @@ -1,7 +1,8 @@ -SELECT name -FROM world -WHERE gdp > - (SELECT - MAX(gdp) - FROM world - WHERE continent LIKE 'Europe') \ No newline at end of file +SELECT w.name +FROM world w +JOIN ( + SELECT MAX(w2.gdp) AS max_gdp + FROM world w2 + WHERE w2.continent = 'Europe' +) europe_max +ON w.gdp > europe_max.max_gdp;