์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[HackerRank] Average Population of Each Continent (SQL/JOIN)

PROGRAMMING/Database

by koharin 2021. 2. 1. 12:07

๋ณธ๋ฌธ

728x90
๋ฐ˜์‘ํ˜•

๐Ÿ’ป Oracle ์ œ์ถœ์ฝ”๋“œ


SELECT A.CONTINENT, FLOOR(AVG(B.POPULATION))
FROM COUNTRY A
JOIN CITY B
ON A.CODE = B.COUNTRYCODE
GROUP BY A.CONTINENT;
  • SELECT: ๋ชจ๋“  ๋Œ€๋ฅ™์˜ ์ด๋ฆ„(COUNTRY.Continent)๊ณผ ๋„์‹œ ์ธ๊ตฌ์ˆ˜์˜ ํ‰๊ท (CITY.Population)์„ ์กฐํšŒํ•œ๋‹ค. ์ด๋•Œ ํ‰๊ท ์€ ๊ฒฐ๊ณผ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ตœ๋Œ€ ์ •์ˆ˜์ด๋‹ค. (FLOOR)

  • FROM ~ JOIN: COUNTRY์™€ CITY ํ…Œ์ด๋ธ”์—์„œ

  • ON: CITY.CountryCode์™€ COUNTRY.Code๊ฐ€ ๋งค์นญ๋œ๋‹ค.

  • GROUP BY: CONTINENT๋ณ„๋กœ ํ‰๊ท ์„ ๊ตฌํ•ด์•ผ ํ•˜๋ฏ€๋กœ CONTINENT๋กœ ๊ทธ๋ฃนํ™”ํ•œ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ