Note: CITY.CountryCode and COUNTRY.Code are matching key columns.
Input Format
The CITY and COUNTRY tables are described as follows:
Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'.
SELECT
SUM(A.POPULATION)
FROM
CITY AS A INNER JOIN COUNTRY AS B
ON A.COUNTRYCODE = B.CODE
WHERE B.CONTINENT = 'Asia';
Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.
SELECT
A.NAME
FROM
CITY AS A INNER JOIN COUNTRY AS B
ON A.COUNTRYCODE = B.CODE
WHERE B.CONTINENT = 'Africa';
Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.
SELECT
B.CONTINENT, TRUNCATE(AVG(A.POPULATION), 0)
FROM
CITY AS A INNER JOIN COUNTRY AS B
ON A.COUNTRYCODE = B.CODE
GROUP BY B.CONTINENT;
'MYSQL 코테 준비' 카테고리의 다른 글
[HacKerRank SQL] SQL Project Planning - MYSQL (0) | 2021.03.09 |
---|---|
[HacKerRank SQL] Ollivander's Inventory - MYSQL (0) | 2021.02.25 |
[HacKerRank SQL] Top Competitors - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] The Report - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] New Companies- MYSQL (0) | 2021.02.19 |
댓글