๋ฌธ์
https://www.hackerrank.com/challenges/weather-observation-station-8/problem
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.
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 A.CITY
FROM (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%') A
WHERE A.CITY LIKE '%A'
OR A.CITY LIKE '%E'
OR A.CITY LIKE '%I'
OR A.CITY LIKE '%O'
OR A.CITY LIKE '%U'
์ฝ๋๊ฐ ๋๋ฌด ๋นํจ์จ์ ์ธ ๊ฒ ๊ฐ์ ๋ค๋ฅธ ํ์ด๋ฅผ ํ์ธํด๋ณด์๋ค.
ํ์ ์ ์ธ ์ฝ๋ ๋ฐ๊ฒฌ, SQL์์๋ ์ ๊ท์์ด ํ์ฉ ๊ฐ๋ฅํ๋ค๋...!
SELECT DISTINCT city
FROM station
WHERE city REGEXP '[aeiou]$' and city REGEXP '^[aeiou]' -- ^์ ์์, $๋ []์ or์ ์๋ฏธํจ
์๋ ๋งํฌ์์ MYSQL์ ์ ๊ท์ ํ์ฉ ๋ฐฉ๋ฒ์ ๊ฐ๋จํ๊ฒ ์ดํด๋ณผ ์ ์๋ค.
์ด์ ์ ์ธํด ํ๋์ ํ๋ฉด์ LIKE ์ ๋ก ์์์ด ํค์๋๋ฅผ ๋ฌถ์๋ ๊ธฐ์ต์ด๋๋ค. ์ด๊ฑธ ๊ฐ๋จํ๊ฒ ์ ๊ท์์ผ๋ก ๋ง๋ค ์ ์์์ ํ
๋ฐ..
https://yurimkoo.github.io/analytics/2019/10/26/regular_expression.html
'Algorithm > SQL Query test' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[MySQL] HackerRank - Weather Observation Station 10 (0) | 2021.07.22 |
---|---|
[MySQL] HackerRank - Weather Observation Station 9 (0) | 2021.07.22 |
[MySQL] HackerRank - Weather Observation Station 7 (0) | 2021.07.22 |
[MySQL] HackerRank - Weather Observation Station 6 (0) | 2021.07.22 |
[MySQL] HackerRank - Weather Observation Station 5 (0) | 2021.07.22 |