SQL

[HackerRank] Weather Observation Station 7

빠르게 핵심만 2024. 2. 25. 16:27
 

Weather Observation Station 7 | HackerRank

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION.

www.hackerrank.com

 

풀이

STATION 테이블에서 모음(a, e, i, o, u)으로 끝나는 도시 이름을 조회하는 방법을 알아보겠습니다.

 

1. RIGHT 함수 사용

SELECT DISTINCT city
FROM station
WHERE RIGHT(city, 1) IN ('a', 'e', 'i', 'o', 'u')

 

2. 정규표현식 사용

SELECT DISTINCT city
FROM station
WHERE city REGEXP '[aeiou]$'

 

3. LIKE 사용

# 권장하지 않습니다.
SELECT DISTINCT city
FROM station
WHERE 
    city LIKE '%a' OR
    city LIKE '%e' OR
    city LIKE '%i' OR
    city LIKE '%o' OR
    city LIKE '%u'