HAZEL

[SQL : 정규표현식 ] HackerRank : Weather Observation Station 6 / 9 본문

DATA ANALYSIS/SQL

[SQL : 정규표현식 ] HackerRank : Weather Observation Station 6 / 9

Rmsid01 2021. 5. 15. 16:59

Weather Observation Station 6


>> 문제

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.

 

>>  기본적으로 푸는 방법

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%'

 

>> 정규표현식을 사용해서 푸는 법

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

' . ' : 어떤문자임에도 다 매치를 시켜준다는 의미

' ^ ' : Beginning Match . ^ 를 입력하면, 맨 앞글자가 왔을 때에만 매치를 시켜준다.

 

SQL 에서는 대소문자에 대해서 예민하지 않기 때문에 , abcd 와 ABCD 가 같은 의미를 가진다. 

 

 

 

 

https://www.hackerrank.com/challenges/weather-observation-station-6/problem?h_r=internal-search 

 

Weather Observation Station 6 | HackerRank

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

www.hackerrank.com

 

Weather Observation Station 9


>> 문제

Query the list of CITY names from STATION that do not start with vowels. 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.

 

>> 문제 풀이

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

 

: NOT 만 붙이면 간단하게, 원하는 것의 반대를 수행할 수 있다.

 

 

* 정규표현식을 공부하기 위한 홈페이지

https://regexone.com/lesson/letters_and_digits

 

RegexOne - Learn Regular Expressions - Lesson 1½: The 123s

Characters include normal letters, but digits as well. In fact, numbers 0-9 are also just characters and if you look at an ASCII table, they are listed sequentially. Over the various lessons, you will be introduced to a number of special metacharacters use

regexone.com

https://regexr.com/

 

RegExr: Learn, Build, & Test RegEx

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

regexr.com