반응형

@notepad_jj2

츄르사려고 코딩하는집사입니다.


1. [HackerRank] Weather Observation Station 4 SQL

 

2. 문제 출처

https://www.hackerrank.com/challenges/weather-observation-station-3/problem

 

Weather Observation Station 3 | HackerRank

Query a list of unique CITY names with even ID numbers.

www.hackerrank.com

 

3. 문제

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 .

 

4. 풀이

- COUNT()함수를 통해 데이터의 갯수를 파악하고, DISTINCT를 사용하여 CITY의 중복된 것을 제거한 데이터의 갯수를 파악한다.

- 그래서, 앞에 있는 것을 중복제거한 데이터의 갯수를 빼면 된다.

 

5. 소스 코드

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

- DISTINCT는 중복을 제거해 준다.


반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기