HackerRank-My SQL

Prepare > SQL > Basic Select > Weather Observation Station 8

stem_sw 2023. 7. 12. 20:23
 

Weather Observation Station 8 | HackerRank

Query CITY names that start AND end with vowels.

www.hackerrank.com

 

문제


Query the list of CITY names from STATION which have vowels (i.e., aeio, and u) as both their first and last characters. Your result cannot contain duplicates.

 

 

 

 

코드


SELECT DISTINCT(CITY) FROM STATION
WHERE LEFT(CITY,1) REGEXP "A|E|I|O|U" AND RIGHT(CITY,1) REGEXP "A|E|I|O|U";

 

 

 

 

노트


SELECT DISTINCT(CITY) FROM STATION
WHERE CITY REGEXP '^[AEIOU].*[AEIOU]$'
  • ^: 문자열의 제일 앞을 나타냄
  • .: 한자리를 차지하는 와일드 카드
  • * 반복을 의미
  • $: 문자열의 제일 마지막을 나타냄