~고군분투 인생살이~

[EASY] Weather Observation Station 6 본문

SQL/HACKER_RANK

[EASY] Weather Observation Station 6

소금깨 2022. 5. 29. 14:17

1. 문제 설명 

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:

where LAT_N is the northern latitude and LONG_W is the western longitude.

 

2. 문제 풀이 

이번에는 기존 like와 더불어 정규 표현식으로 해당 문제를 풀어보려고 합니다.

 

정규표현식에 대한 더 자세한 설명은 아래의 사이트를 참고하자.

 

RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, and the ABCs

Regular expressions are extremely useful in extracting information from text such as code, log files, spreadsheets, or even documents. And while there is a lot of theory behind formal languages, the following lessons and examples will explore the more prac

regexone.com

 

 

RegExr: Learn, Build, & Test RegEx

RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).

regexr.com

3. 결과 

기존 like 방식 

SELECT city
FROM STATION
WHERE state like 'a%' 
OR state like 'e%'
OR state like 'i%'
OR state like 'o%'
OR state like 'u%'

 

정규 표현식

select distinct city
from station
where city regexp '^[AEIOUaeiou].*' --SQL은 대소문자에 까다롭지 않기 때문에 소문자만 기입해도 된다.

 

'SQL > HACKER_RANK' 카테고리의 다른 글

[HACKER_RANK] THE-PADS  (0) 2022.06.13
[EASY] Weather Observation Station 9  (0) 2022.05.29
[EASY] Weather Observation Station 8  (0) 2022.05.29
[EASY] Weather Observation Station 7  (0) 2022.05.29
[HACKER_RANK] THE REPORT  (0) 2022.05.01
Comments