inblog logo
|
silver
    SQL문제풀기

    [SQL문제풀기] Weather Observation Station 6

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

    문제

    Weather Observation Station 6 | HackerRank
    Query a list of CITY names beginning with vowels (a, e, i, o, u).
    Weather Observation Station 6 | HackerRank
    https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true
    Weather Observation Station 6 | HackerRank

    MySQL

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

    내가 작성한 정답1 - like

    select city from station where city like 'i%' or city like 'e%' or city like 'a%' or city like 'o%' or city like 'u%';

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

    select city from station where city regexp '^[aeiou]'; // ^: 문자열의 시작

    내가 작성한 정답3 - substring

    select city from station where substring(city,1,1) in ('a','e','i','o','u');

    내가 작성한 정답4 - left

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

    Oracle

    : 대소문자 구분 필요

    내가 작성한 정답1 - like

    : 도시의 첫글자는 대문자
    select city from station where city like 'I%' or city like 'E%' or city like 'A%' or city like 'O%' or city like 'U%';

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

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

    내가 작성한 정답3 - substr

    select city from station where lower(substr(city,1,1)) in ('a','e','i','o','u');

    MS SQL Server - MySQL과 유사

    : 대소문자 구분 x

    내가 작성한 정답1 - like

    select city from station where city like 'i%' or city like 'e%' or city like 'a%' or city like 'o%' or city like 'u

    내가 작성한 정답2 - like2

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

    내가 작성한 정답3 - substring

    select city from station where substring(city,1,1) in ('a','e','i','o','u');

    내가 작성한 정답4 - left

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

    DB2 - Oracle과 유사

    내가 작성한 정답1 - like

    select city from station where city like 'I%' or city like 'E%' or city like 'A%' or city like 'O%' or city like 'U%';

    내가 작성한 정답2 - substr

    select city from station where lower(substr(city,1,1)) in ('a','e','i','o','u');

    정리!

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

    silver

    RSS·Powered by Inblog