> 개발-IT-인터넷/> SQL

[해커랭크(HackerRank) SQL 풀이] - Weather Observation Station 9

jini:) 2023. 11. 1. 10:17
728x90
반응형
해커 랭크 - https://www.hackerrank.com/
Prepare > SQL > Basic Select > Weather Observation Station 9

 

 

HackerRank - Online Coding Tests and Technical Interviews

HackerRank is the market-leading coding test and interview solution for hiring developers. Start hiring at the pace of innovation!

www.hackerrank.com

 

 

STATION에서 자음으로 시작하는 CITY 이름을 조회합니다.

중복된 결과가 포함되지 않아야 합니다.

 

Input Format

STATION 테이블은 다음과 같이 설명됩니다.

[출처] https://www.hackerrank.com/challenges/weather-observation-station-9/problem

 

여기서 LAT_N은 북위, LONG_W는 서경입니다.

 

반응형

 

MySQL
SELECT  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%')
GROUP BY CITY;

 

Oracle
SELECT  CITY
FROM    STATION
WHERE   (LOWER(CITY) NOT LIKE 'a%'
         AND LOWER(CITY) NOT LIKE 'e%'
         AND LOWER(CITY) NOT LIKE 'i%'
         AND LOWER(CITY) NOT LIKE 'o%'
         AND LOWER(CITY) NOT LIKE 'u%')
GROUP BY CITY;

 

MS SQL Server
SELECT  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%')
GROUP BY CITY;

 

 


  • MySQL과 MSSQL의 경우 NOT LIKE 조건 검색 시 대소문자 구분 따로 없어도 조회 가능.
  • ORACLE의 경우 NOT LIKE 조건 검색 시 대소문자 구분 필요함. 여기서는 소문자로 치환하여 조회함.

 

  • 대문자로 치환하여 검색 시 : UPPER()
  • 소문자로 치환하여 검색 시 : LOWER()

 

 

개인 공부를 위한 포스팅입니다.
모든 번역, 코드는 완벽하지 않을 수 있습니다.

 

 

728x90
반응형