코딩 연습/SQL

[HackerRank] Weather Observation Station 시리즈 뒷부분

썬2 2021. 4. 2. 16:35

Like와 In을 같이 쓰고 싶은데 뚜렷한 방법은 없더라.

누군가 정규포현식을 썼긴했는데 크게 맘에 들지 않아 일단 아래와 같이 나열하듯이 했다.

참고로 정규표현식으로 하는 방법은 아래와 같다.

SELECT City
FROM Station
WHERE City REGEXP '^[aeiou]' and City REGEXP '[aeiou]$';

모음으로 시작(^)하는 단어 선택, 모음으로 끝($)나는 단어 선택

 

# Weather Observation Station 6
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%'
order by city;

# Weather Observation Station 7
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'
order by city;

# Weather Observation Station 8
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%')
    and
    (city like '%a' or
    city like '%e' or
    city like '%i' or
    city like '%o' or
    city like '%u') 
order by city;

# Weather Observation Station 9
select distinct(city)
from station
where city not like 'a%' and
    city not like 'e%' and
    city not like 'i%' and
    city not like 'o%' and
    city not like 'u%'
order by city;

# Weather Observation Station 10
select distinct(city)
from station
where city not like '%a' and
    city not like '%e' and
    city not like '%i' and
    city not like '%o' and
    city not like '%u'
order by city;

# Weather Observation Station 11
select distinct(city)
from station
where (city not like 'a%' and
    city not like 'e%' and
    city not like 'i%' and
    city not like 'o%' and
    city not like 'u%')
    or
    (city not like '%a' and
    city not like '%e' and
    city not like '%i' and
    city not like '%o' and
    city not like '%u') 
order by city;

# Weather Observation Station 12
select distinct(city)
from station
where (city not like 'a%' and
    city not like 'e%' and
    city not like 'i%' and
    city not like 'o%' and
    city not like 'u%')
    and
    (city not like '%a' and
    city not like '%e' and
    city not like '%i' and
    city not like '%o' and
    city not like '%u') 
order by city;