inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] Weather Observation Station 12

    silver's avatar
    silver
    Apr 09, 2025
    [SQL문제풀기] Weather Observation Station 12
    Contents
    문제MySQLOracleMS SQL Server - MySQL과 유사DB2 - Oracle과 유사정리!

    문제

    Weather Observation Station 11 | HackerRank
    Query a list of CITY names not starting or ending with vowels.
    Weather Observation Station 11 | HackerRank
    https://www.hackerrank.com/challenges/weather-observation-station-11/problem?isFullScreen=true
    Weather Observation Station 11 | HackerRank

    MySQL

    : 대소문자 구분하지 않아도 됨

    내가 작성한 정답1 - like

    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');

    내가 작성한 정답2 - 정규표현식

    select distinct city from station where city not regexp '^[aeiou]' or city not regexp '[aeiou]$';

    내가 작성한 정답3 - substring, substr 둘 다 사용가능

    select distinct city from station where substring(city,1,1) not in ('a','e','i','o','u') or substring(city,-1,1) not in ('a','e','i','o','u'); select distinct city from station where substr(city,1,1) not in ('a','e','i','o','u') or substr(city,-1,1) not in ('a','e','i','o','u');

    내가 작성한 정답4 - left & right

    select distinct city from station where left(city,1) not in ('a','e','i','o','u') or right(city,1) not in ('a','e','i','o','u');

    Oracle

    : 대소문자 구분 필요

    내가 작성한 정답1 - like

    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');

    내가 작성한 정답2 - 정규표현식 regexp_like

    select distinct city from station where not regexp_like(lower(city),'^[aeiou]') or not regexp_like(city,'[aeiou]$');

    내가 작성한 정답3 - substr

    select distinct city from station where substr(city,1,1) not in ('A','E','I','O','U') or substr(city,-1,1) not in ('a','e','i','o','u');

    MS SQL Server - MySQL과 유사

    : 대소문자 구분 x

    내가 작성한 정답1 - like

    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');

    내가 작성한 정답2 - like2

    select distinct city from station where city not like '[aeiou]%' or city not like '%[aeiou]';

    내가 작성한 정답3 - left & right

    select distinct city from station where left(lower(city),1) not in ('a','e','i','o','u') or right(city,1) not in ('a','e','i','o','u');

    DB2 - Oracle과 유사

    내가 작성한 정답 - like

    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');

    정리!

    💡
    DBMS
    문자추출
    left 유무
    정규표현식
    MS SQL Server
    substring - 음수지원 X
    o
    x → like로 표현가능
    MySQL
    substring - 음수 지원
    o
    o → regexp
    Oracle
    substr - 음수 지원
    x
    o → regexp_like(colunm,정규식)
    DB2
    substr - 음수 지원 X
    x
    x → substr로 표현가능
     
    Share article

    silver

    RSS·Powered by Inblog