융무의 기술블로그
article thumbnail

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.

Note: CITY.CountryCode and COUNTRY.Code are matching key columns.

Input Format

The CITY and COUNTRY tables are described as follows:

  • join two tables ==> FROM CITY AS i JOIN COUNTRY AS o ON i.COUNTRYCODE=o.CODE
  • query names of continents ==> SELECT o.CONTINENT
  • respective city average population ==> AVG(i.POPULATION) … GROUP BY o.CONTINENT
  • round down to nearest integer ==> FLOOR(AVG(i.POPULATION)) … GROUP BY o.CONTINENT
SELECT O.CONTINENT, FLOOR(AVG(I.POPULATION)) 
FROM CITY AS I 
JOIN COUNTRY AS O ON I.COUNTRYCODE=O.CODE 
GROUP BY O.CONTINENT;

'Algorithm > SQL' 카테고리의 다른 글

[SQL][HackerRank] Draw The Triangle 2  (0) 2020.06.14
[SQL][HackerRank] Draw The Triangle 1  (0) 2020.06.14
[SQL][HackerRank]African Cities  (0) 2020.06.13
[SQL][HackerRank] Asian Population  (0) 2020.06.13
[SQL][HackerRank] The Report  (0) 2020.06.12
profile

융무의 기술블로그

@융무

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!