문제
Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
코드
SELECT COUNT(city) - COUNT(DISTINCT(city))
FROM station
풀이
- 전체 city에서 중복되지 않는 city값 빼기 = 중복되는 city 수
- city의 총 개수를 세고 city 이름들을 중복하지 않게 세서 차이를 보고 싶다
출처
반응형
'Algorithm > MySQL' 카테고리의 다른 글
[해커랭크(Hacker Rank)] Type of Triangle (MySQL) (0) | 2021.06.30 |
---|---|
[해커랭크(Hacker Rank)] Top Earners (MySQL) (0) | 2021.06.30 |
[해커랭크(Hacker Rank)]Population Density Difference (MySQL) (0) | 2021.06.30 |
[해커랭크(Hacker Rank)]Average Population (MySQL) (0) | 2021.06.30 |
[해커랭크(Hacker Rank)]Revising Aggregations - The Count Function (MySQL) (0) | 2021.06.30 |