SQL

[해커랭크] Weather Observation Station 10([^]=not)

주스 JUICE 2023. 7. 8. 00:22
728x90

아니 저번 글에 바로

^을 두 번 쓰면 not 기능이 있다고 썼는데

10을 풀면서 아.. 대괄호 안에 ^을 쓰면 not 기능이 있다는 걸 깨달음

 

 

 

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

 

Weather Observation Station 10 | HackerRank

Query a list of CITY names not ending in vowels.

www.hackerrank.com

 

 

내 처음 답변(오답)

 

SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '[aeiou$]$'

내 생각)

앞에 오는 게 ^로 표현됐으니까

마지막 글자 아닌 걸 표현하려면 $겠지?

그럼 $을 대괄호 안밖 둘 다 써야겠지?

아님

 

 

다음 내 답변(정답)

 

select distinct city
from station
where city not regexp '[aeiou]$'

결국 not regexp 써서 밖에만 $ 붙임

 

 

 

 

다른 사람 정답 답변

select distinct CITY from STATION where CITY RLIKE '[^aeiou]$'

대괄호 안에 ^ 쓰면 not 기능을 하는군아..

새로 알았다

728x90