SQL

HackerRank_SQL_Weather Observation Station 12

응엉잉 2023. 1. 5. 14:07

https://www.hackerrank.com/challenges/weather-observation-station-12/problem?isFullScreen=true

 

Weather Observation Station 12 | HackerRank

Query an alphabetically ordered list of CITY names not starting and ending with vowels.

www.hackerrank.com

SELECT DISTINCT city
FROM station
WHERE city NOT LIKE 'a%'
    AND city NOT LIKE 'e%'
    AND city NOT LIKE 'i%'
    AND city NOT LIKE 'o%'
    AND city NOT LIKE 'u%'
    AND city NOT LIKE '%a'
    AND city NOT LIKE '%e'
    AND city NOT LIKE '%i'
    AND city NOT LIKE '%o'
    AND city NOT LIKE '%u'

복붙 없이 코드를 짜려면 정규표현식을 사용해야 함

 

정규표현식 (regular expression -> REGEXP)

문자열에서 특정 패턴을 찾아내는데 쓰이는 식

SELECT DISTINCT city
FROM station
WHERE city REGEXP '^[aeiou].*'

^ 는 시작

.*는 와일드카드(%)와 동일