반응형
츄르사려고 코딩하는집사입니다.
1. [HackerRank] Weather Observation Station 4 SQL
2. 문제 출처
https://www.hackerrank.com/challenges/weather-observation-station-3/problem
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는 중복을 제거해 준다.
반응형
'알고리즘 > HackerRank' 카테고리의 다른 글
[HackerRank] Weather Observation Station 8 오라클(Oracle) (0) | 2021.09.08 |
---|---|
[HackerRank] Weather Observation Station 7 오라클(Oracle) (0) | 2021.09.07 |
[HackerRank] Weather Observation Station 6 오라클(Oracle) (0) | 2021.09.07 |
[HackerRank] Weather Observation Station 5 SQL (0) | 2021.09.07 |
[HackerRank] Weather Observation Station 3 SQL (0) | 2021.09.06 |
[HackerRank] Weather Observation Station 1 SQL (0) | 2021.09.06 |
[HackerRank] Japanese Cities' Names SQL (0) | 2021.09.06 |
[HackerRank] Japanese Cities' Attributes SQL (0) | 2021.09.06 |
최근댓글