OkBublewrap

Weather Observation Station 9 본문

개발/SQL

Weather Observation Station 9

옥뽁뽁 2023. 2. 22. 08:46

Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.

Input Format

The STATION table is described as follows:

모음으로 시작하지 않은 city 이름, 중복 불가

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%'

NOT LIKE 연산자를 사용을 하면 된다.

 

정규식 연습

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

REGEXP는 LIKE를 안써도 되는 것을 알았다. NOT LIKE 같이 해야하는 줄 알았는데 그게 아니였다.

"." 은 문자 하나를 뜻하고 *은 갯수 였다. 그래서 ".*"을 같이 쓰게 되면 문자열을 갖고 올 수 있게 되는 것이다.

'개발 > SQL' 카테고리의 다른 글

Weather Observation Station 11  (0) 2023.02.22
Weather Observation Station 10  (0) 2023.02.22
Weather Observation Station 8  (0) 2023.02.22
Weaher Observation Station 7  (0) 2023.02.22
Weather Observation Station 5  (0) 2023.02.22