본문 바로가기

Algorithm/MySQL

[해커랭크(HackerRank)] Weather Observation Station 8 (MySQL)

문제

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:

코드

  • Substring
Select distinct city
From Station
Where substring(city, 1, 1) IN ('a','e','i','o','u')
And substring(city, -1) IN ('a','e','i','o','u')
  1. Station 테이블에서 city이름의 첫글자와 끝글자가 모음인 컬럼 출력
  2. 중복 금지
  • 정규표현식
SELECT distinct city
FROM station
WHERE city REGEXP '^[aeiou].*'
AND city REGEXP '.*[aeiou]$'
SELECT distinct city
FROM station
WHERE city REGEXP '^[aeiou].*[aeiou]$'

출처

반응형