Revising Aggregations-Averages
문제: Query the average population of all cities in CITY where District is California.
풀이: district가 California인 CITY의 인구 수의 평균을 구하는 문제. AVG 함수로 간단히 해결할 수 있다.
SELECT AVG(POPULATION) AS cali_avg FROM CITY WHERE DISTRICT = 'California'; |
Average Population
문제: Query the average population for all cities in CITY, rounded down to the nearest integer.
풀이: CITY의 모든 도시들에 대해 평균을 구하는데 반올림 해서 정수로 구하는 문제.
Japan Population
문제: Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN.
풀이: CITY에 있는 모든 일본 도시의 인구 합계를 구하는 문제. WHERE절에 COUNTRYCODE 조건을 주고 SUM 함수로 구하기!
SELECT SUM(POPULATION) FROM CITY WHERE COUNTRYCODE = 'JPN'; |
'Database' 카테고리의 다른 글
해커랭크 SQL문제_0828 (0) | 2021.08.28 |
---|---|
Stored Function (0) | 2021.08.28 |
해커랭크 SQL문제_0805 (0) | 2021.08.05 |
해커랭크 SQL문제_0804 (0) | 2021.08.04 |
해커랭크 SQL문제_0803 (0) | 2021.08.03 |