Doubt
Is there any method for sorting in difficulty levels, an SQL query in easy, medium, or difficult ? This question may be a bit subjective, but speculating may be a good option.
Context
I was responding to some SQL issues on the hackerrank site and came across a " basic" question > "about JOIN considered" easy ", but I took some time to do it and would like to share the experience.
Here's the question: Given a CITY and COUNTRY table, make a query that shows the sum of the population where the continent is "Asia." ask english
Myresolution
Findthecitiesforthecountry"Asia".
SELECT code FROM country WHERE continent = "Asia";
Map the filtered cities in the COUNTRY table with the CITY table using JOIN .
SELECT code, countrycode, population FROM consulta1 JOIN city ON consulta1.code = city.countrycode;
Add the population of the filtered query
SELECT SUM(population) FROM consulta2;
If you join all sub queries , using ALIAS - AS, we come to the answer.
Response
SELECT SUM(POPULATION) FROM
(SELECT tab1.CODE,CITY.COUNTRYCODE,CITY.POPULATION FROM
( SELECT CODE FROM COUNTRY WHERE CONTINENT = "Asia") AS tab1
JOIN CITY ON tab1.CODE = CITY.COUNTRYCODE) AS tab2;