SQL

[HackerRank]Weather Observation Station 3(SQL코딩테스트 준비)

햄스텅 2022. 8. 6. 21:32

<문제 설명>

Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.

 

 

<풀이>

SELECT DISTINCT CITY
FROM STATION
WHERE MOD(ID, 2) = 0;

1. 중복값이 없도록 출력되어야 한다.

2. ID가 짝수인 것만 출력한다. 

CITY칼럼을 출력하기 때문에 앞에 DISTINT를 사용해서 중복값을 제외했고,

MOD함수를 사용해서 나머지가 0인 (짝수인) 값만을 출력했다.

MOD 함수사용

: MOD(나눠지는 값, 나눌 값)