💻 주소 : https://www.hackerrank.com/challenges/weather-observation-station-8/problem
Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.
Input Format
The STATION table is described as follows:
문제를 해석해보자면 CITY 이름 중에서 맨앞과 맨뒤과 e, a, e, i, o, u 중에 하나여야 한다는 뜻이다.
뭐 해결 방법으로는 나처럼 left, right를 사용하거나 substr을 이용해서 그 부분만 문자를 추출해서 비교하는 방식이 있을 수 있겠다.
두번째 방식으로는 간단하게 정규표현식을 이용하면 된다.
select distinct(city)
from station
where left(city, 1) in ('a', 'e', 'i', 'o', 'u') and right(city, 1) in ('a', 'e', 'i', 'o', 'u')
select distinct(city)
from station
where city regexp '^[aeiou]' and city regexp '[aeiou]$'
정규 표현식을 사용하는게 더 깔끔하고 가독성이 좋아보인다.