🤖 코딩테스트 준비/해커랭크

[SQL] 해커랭크(HackerRank) - Easy2

seoyeun 2022. 9. 4. 12:15

1. Weather Observation Station 1

Query a list of CITY and STATE from the STATION table.
where LAT_N is the northern latitude and LONG_W is the western longitude.

select city, state
from STATION

https://www.hackerrank.com/challenges/weather-observation-station-1/problem?isFullScreen=true 

 

Weather Observation Station 1 | HackerRank

Write a query to print the CITY and STATE for each attribute in the STATION table.

www.hackerrank.com

 

2. Weather Observation Station 6

Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION.
Your result cannot contain duplicates.
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%'
1. 중복을 허용하지 않는다고 했으므로 DISTINCT를 사용해주고
2. 모음으로 시작하는 name을 찾아야 하므로 LIKE 연산자를 이용('a%')

https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true 

 

Weather Observation Station 6 | HackerRank

Query a list of CITY names beginning with vowels (a, e, i, o, u).

www.hackerrank.com

3. Weather Observation Station 12

Query the list of CITY names from STATION that do not start with vowels and do not end with vowels.
Your result cannot contain duplicates.
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'
1. 중복을 허용하지 않는다고 했으므로 DISTINCT를 사용해주고
2. 모음으로 시작하지 않는 name을 찾아야 하므로 NOT LIKE 연산자를 이용('a%')
3. 모음으로 끝나지 않는 name을 찾아야 하므로 NOT LIKE 연산자를 이용('%a')

https://www.hackerrank.com/challenges/weather-observation-station-12/problem?isFullScreen=true 

 

Weather Observation Station 12 | HackerRank

Query an alphabetically ordered list of CITY names not starting and ending with vowels.

www.hackerrank.com