SQL/HackerRank

[HackerRank] Weather Observation Station 4

햄습햄 2022. 1. 19. 15:58

문제 설명 (Difficulty: Easy)

 

Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

(테이블에 있는 CITY 총 항목 수와 고유한 CITY 항목 수 사이의 차이를 찾으세요.)


The STATION table is described as follows:

(STATION 테이블은 다음과 같이 설명됩니다.)

where LAT_N is the northern latitude and LONG_W is the western longitude.

(여기서 LAT_N은 북쪽 위도이고, LONG_W는 서쪽 경도입니다.)

 

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'.

(예를 들어, 만약 테이블에서 도시 값 'New York', 'New York', 'Bengalaru' - 3개 항목이 있다면,

2개의 다른 도시 이름 - 'New York', 'Bengalaru'가 있는 것입니다.)

 

The query returns 1, because total number of records - number of unique city names = 3 - 2 =1.

(총 항목 수에서 고유한 도시 이름 수 를 빼면, 3 -2 = 1이기 때문에 쿼리는 1을 반환합니다.)

 


풀이 과정 (MySQL)