반응형
▶ SQL > Aggregation > Japan Population
Problem
Query the sum of the populations for all Japanese cities in CITY. The COUNTRYCODE for Japan is JPN.
Input Format
The CITY table is described as follows:
My Answer
SELECT SUM(POPULATION)
FROM CITY
WHERE COUNTRYCODE = 'JPN'
NOTE
- SUM(필드명) : 필드 값을 더할 때 사용하는 함수
- COUNT(필드명) : NULL이 아닌 레코드의 수
COUNT(*)은 레코드의 개수를 나타내지만 SUM(*)은 오류
반응형
'CODING TEST > SQL : HackerRank' 카테고리의 다른 글
[MYSQL] Weather Observation Station 2 (0) | 2021.08.09 |
---|---|
[MYSQL] Top Earners (0) | 2021.05.26 |
[MYSQL] The Blunder (0) | 2021.05.18 |
[MYSQL] Population Density Difference (0) | 2021.05.13 |
[MySQL] Average Population (0) | 2021.04.21 |
[MySQL] Revising Aggregations - Averages (0) | 2021.04.20 |
[MySQL] Revising Aggregations - The Count Function (0) | 2021.04.20 |
[MySQL] Employee Salaries (0) | 2021.04.15 |
댓글