DevHyun

Weather Observation Station 4 본문

SQL/HACKERRANK

Weather Observation Station 4

D3V3L0P3R 2020. 10. 29. 14:11

www.hackerrank.com/domains/sql

 

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 .

 

total number of records - number of unique city names = 3 - 2 = 1

 

번역 : STATION 테이블에서 CITY의 총 갯수에서 중복제거된 CITY의 갯수를 뺀 값은?

 

MSSQL

 

풀이 : 예를들면 STATION 테이블의 총 COUNT는 3이고 각각 값들이 KOREA, JAPAN, KOREA라면 중복제거된 CITY의 갯수는 2일 것임!

 

이런 계산은 처음해봐서 당황했다!

나의 첫 답은 SELECT COUNT(*) - COUNT(CITY) FROM STATION 이었는데

완전히 달랐음... 문제 이해를 잘 못했던 것 같음! 

 

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

'SQL > HACKERRANK' 카테고리의 다른 글

Occupations  (0) 2020.11.03
Print Prime Numbers  (0) 2020.10.29
Draw The Triangle 1  (0) 2020.10.29
Weather Observation Station 5  (0) 2020.10.29
Weather Observation Station 3  (0) 2020.10.29
Comments