Analysis & Visualization/SQL
[SQL] HackerRank - Weather Observation Station 6
statsbymin
2022. 7. 25. 07:40
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.
문제요약
더보기
STATION 테이블 CITY컬럼 이름이 모음으로 시작하는 컬럼을 중복없이 출력
풀이
1. 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%';
더보기
- LIKE 문과 OR 연산자를 활용
- 'a%'에서 %는 a 뒤에 0개 이상의 문자가 있음을 의미
2. 정규표현식 REGEXP 사용
select distinct city
from station
where city regexp '^[aeiou]';
더보기
- 조건이 많아질수록 1번 풀이의 코드가 길어지고 비효율적일 수 있기 때문에 정규표현식(REGEXP)을 활용
- ^는 [ ] 안에 a, e, i, o, u로 시작하는 문자열을 찾을 떄 사용
결과
HackerRank
HackerRank is the market-leading technical assessment and remote interview solution for hiring developers. Learn how to hire technical talent from anywhere!
www.hackerrank.com