새소식

SQL/해커랭크

[MySQL] Weather Observation Station 4

  • -

[문제]
https://www.hackerrank.com/challenges/weather-observation-station-4/problem?isFullScreen=true

 

Weather Observation Station 4 | HackerRank

Find the number of duplicate CITY names in STATION.

www.hackerrank.com


[문제 풀이]


조건 1. 전체 city 갯수를 조회하자.

조건 2. 전체 city의 중복되지 않은 갯수를 조회하자.
조건 3. 전체 city에서 중복되지 않은 갯수를 빼자.

 

MySQL에서는 '-' 을 이용해서 뺄셈을 보여줄 수가 있다.

DISTINCT 와 - 을 이용해서 만들어보자.


[코드]

select COUNT(CITY)- COUNT(DISTINCT CITY)
from station

 

'SQL > 해커랭크' 카테고리의 다른 글

[MySQL] Weather Observation Station 6  (0) 2022.10.09
[MySQL] Weather Observation Station 5  (0) 2022.10.09
[MySQL] Weather Observation Station 3  (0) 2022.10.09
[MySQL] Weather Observation Station 1  (0) 2022.10.09
[MySQL] Japanese Cities' Names  (0) 2022.10.09
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.