본문 바로가기

Algorithm/MySQL

[해커랭크(Hacker Rank)] Weather Observation Station 4 (MySQL)

문제

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

 

풀이

  1. 전체 city에서 중복되지 않는 city값 빼기 = 중복되는 city 수
  2. city의 총 개수를 세고 city 이름들을 중복하지 않게 세서 차이를 보고 싶다

 

출처

반응형