문제 URL : https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true
Weather Observation Station 6 | HackerRank
Query a list of CITY names beginning with vowels (a, e, i, o, u).
www.hackerrank.com
문제 설명 : station 테이블의 city컬럼의 데이터값중에 이름으로 a ,i,e,o,u 로 시작하는데이터를 출력하라는뜻인데
like로 사용하니
select city from station
where city like 'a%' or city like 'e%' or city like 'i%' or city like 'o%' or city like 'u%'
이렇게 됐다. 코드가 너무 꼴보기 싫어서
like랑 in을 같이 사용할수있는 방법을 찾아봤는데 없더니
regexp라는 명령어를 알게됐다. 정규식을 이용할수 있도록 하는건데
정규식을 이용할줄안다면 쉽게 짤수있당
select city from station
where city regexp '^(a|e|i|o|u).*$'
코드가 너무깔끔하다 ㅋㅋㅋ
'HackerRank' 카테고리의 다른 글
해커랭크 The PADS (0) | 2022.12.15 |
---|---|
해커랭크 Top Earners (0) | 2022.12.15 |
해커랭크 Weather Observation Station 5 ->Mysql (0) | 2022.11.30 |