Im between cherry

Hackerrank | MySQL | Weather Observation Station 6 본문

데이터분석/practice_query

Hackerrank | MySQL | Weather Observation Station 6

meal 2020. 8. 27. 18:20

Weather Observation Station 6

Problem

 

Weather Observation Station 6 | HackerRank

Query a list of CITY names beginning with vowels (a, e, i, o, u).

www.hackerrank.com

Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.

Input Format

The STATION table is described as follows:

 

 

Solution

-- RLIKE 사용

SELECT DISTINCT city
FROM station
WHERE city RLIKE '^[aeiou]'
-- LIKE사용

SELECT DISTINCT(city)
FROM station
WHERE city LIKE 'a%'
   OR city LIKE 'e%'
   OR city LIKE 'i%'
   OR city LIKE 'o%'
   OR city LIKE 'u%'
-- SUBSTRING 사용

SELECT DISTINCT city
FROM station
WHERE SUBSTRING(city, 1, 1) in ('a','e','i','o','u')

 

Comments