반응형
츄르사려고 코딩하는집사입니다.
1. [HackerRank] Weather Observation Station 5 SQL
2. 문제 출처
https://www.hackerrank.com/challenges/weather-observation-station-3/problem
3. 문제
Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
4. 풀이
- LENGTH() 함수를 통해 길이를 구하고, CITY의 길이로 각 오름차순과 내림차순을 한 다음에, CITY의 알파벳 순서로 오름차순을 하고 1개만 출력한다.
5. 소스 코드
SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) ASC, CITY ASC
LIMIT 1;
SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) DESC, CITY ASC
LIMIT 1
- DISTINCT는 중복을 제거해 준다.
반응형
'알고리즘 > HackerRank' 카테고리의 다른 글
[HackerRank] Weather Observation Station 9 오라클(Oracle) (0) | 2021.09.08 |
---|---|
[HackerRank] Weather Observation Station 8 오라클(Oracle) (0) | 2021.09.08 |
[HackerRank] Weather Observation Station 7 오라클(Oracle) (0) | 2021.09.07 |
[HackerRank] Weather Observation Station 6 오라클(Oracle) (0) | 2021.09.07 |
[HackerRank] Weather Observation Station 4 SQL (0) | 2021.09.06 |
[HackerRank] Weather Observation Station 3 SQL (0) | 2021.09.06 |
[HackerRank] Weather Observation Station 1 SQL (0) | 2021.09.06 |
[HackerRank] Japanese Cities' Names SQL (0) | 2021.09.06 |
최근댓글