🐬 MySQL/문제풀이

[MySQL] 해커랭크 집계함수 연습 (Weather Observation Station 4)

xod22 2023. 1. 25. 15:07
728x90

1. 문제

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.

For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns , because .

 

문제가 어려워보이지만 간단하게 정리하면

(the number of cities) - (중복된 값을 포함하지 않은 값)

 

 

 

2. 내풀이

SELECT COUNT(CITY) - COUNT(DISTINCT CITY)
FROM STATION

 

 

 

3. 결과

728x90