Weather Observation Station 4
Problem
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 descrived as follows:
(테이블 내 CITY 항목의 총 개수와 테이블 내 고유 CITY 항목의 수 사이의 차이를 찾으시오.)
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 1, because
total number of records - number of unique city names = 3 - 2 = 1
(예를들어, CITY값에 'New York', 'New York', 'Bengalaru'의 총 세 개의 레코드가 있다면, 서로 다른 도시 이름은 'New York'과 'Bengalaru' 두 가지이다. 따라서 쿼리는 1을 반환한다.)
Solution(Oracle)
--ver.1
SELECT COUNT(CITY) - COUNT(DISTINCT CITY)
FROM STATION;
--ver.2
SELECT COUNT(ALL CITY) - COUNT(DISTINCT CITY)
FROM STATION;
COUNT 함수 - 데이터 개수를 구함
COUNT(*): 테이블의 총 행 수를 반환. (NULL 값을 포함하는 행도 계산)
COUNT(열 이름): 지정된 열에 NULL이 아닌 값을 가진 행의 수를 반환.
COUNT(DISTINCT 열 이름): 지정된 열에 대해 고유한 값의 수를 반환. (중복제거)
https://www.hackerrank.com/challenges/weather-observation-station-4/problem
Weather Observation Station 4 | HackerRank
Find the number of duplicate CITY names in STATION.
www.hackerrank.com
'SQL' 카테고리의 다른 글
[HackerRank SQL] Weather Observation Station 7 (Oracle) (0) | 2024.03.31 |
---|---|
[HackerRank SQL] Weather Observation Station 6 (Oracle) (0) | 2024.03.30 |
[HackerRank SQL] Weather Observation Station 5 (Oracle) (0) | 2024.03.29 |
[HackerRank SQL] Weather Observation Station 3 (Oracle) (0) | 2024.03.27 |
[HackerRank SQL] Weather Observation Station 1 (Oracle) (0) | 2024.03.26 |