[HackerRank] Weather Observation Station 6~11(정규표현식)

주연·2023년 2월 20일
0

SQL 문제 풀이

목록 보기
16/28
post-thumbnail
post-custom-banner

230220

정규표현식 튜토리얼 https://regexone.com/lesson/introduction_abcs
정규표현식 테스트 https://regexr.com/

튜토리얼에 기본적인 문법은 나와있으니 참고해서 풀자!

Weather Observation Station 6

문제

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

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

풀이

SELECT DISTINCT city
FROM STATION
WHERE city REGEXP '^[aeiou].*' 

Weather Observation Station 7

문제

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

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

풀이

SELECT DISTINCT city
FROM station
WHERE city REGEXP '.*[aeiou]$' 

Weather Observation Station 8

문제

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

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.

풀이

SELECT DISTINCT city
FROM station
WHERE city REGEXP '^[aeiou].*[aeiou]$' 

9-11은 6-8번 반대, NOT만 붙이면 된다.

Weather Observation Station 9

문제

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

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

풀이

SELECT DISTINCT city
FROM station
WHERE city REGEXP '^[^aeiou].*' 
  • 문제 풀이 확인
SELECT DISTINCT city
FROM station
WHERE city NOT REGEXP '^[aeiou].*' 

앞에 NOT 붙이는 것도 가능

Weather Observation Station 10

문제

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

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

풀이

SELECT DISTINCT city
FROM station
WHERE city NOT REGEXP '.*[aeiou]$' 

Weather Observation Station 11

문제

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

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.

풀이

SELECT DISTINCT city
FROM station
WHERE city NOT REGEXP '^[aeiou].*[aeiou]$' 
profile
공부 기록
post-custom-banner

0개의 댓글