[HackerRank|MySQL] Weather Observation Station 6 - 12

히끼·2020년 8월 22일
0

HackerRank

목록 보기
8/13

Weather Observation Station 6

Problem

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

Solution

SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '^[AEIOU]'
SELECT DISTINCT CITY
FROM STATION
WHERE CITY RLIKE '^[AEIOU].*'

Weather Observation Station 7

Problem

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

Solution

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

Weather Observation Station 8

Problem

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.

Solution

SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '^[AEIOU]' AND CITY RLIKE '[AEIOU]$'
SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '^[AEIOU].*[aeiou]$'

Weather Observation Station 9

Problem

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

Solution

SELECT DISTINCT CITY
FROM STATION
WHERE NOT CITY REGEXP '^[AEIOU]'
SELECT DISTINCT CITY
FROM STATION
WHERE CITY NOT REGEXP '^[AEIOU].*'

Weather Observation Station 10

Problem

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

Solution

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

Weather Observation Station 11

Problem

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

Solution

SELECT DISTINCT CITY
FROM STATION
WHERE CITY NOT RLIKE '^[aeiou]'
OR CITY NOT REGEXP '[aeiou]$'

Weather Observation Station 12

Problem

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

Solution

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

0개의 댓글