알고리즘/HackerRank
[HackerRank] Weather Observation Station 5 오라클 풀이
mndev
2024. 1. 29. 10:17
문제링크
Weather Observation Station 5 | HackerRank
Write a query to print the shortest and longest length city name along with the length of the city names.
www.hackerrank.com
풀이
도시이름중 문자열 길이가 가장 긴 값과 짧은 값을 구하기 때문에
각 도시의 이름 별로 정렬하고(오름차순, 내림차순)
가장 위에 있는 하나의 행만 출력하면 문제 조건에 맞게 풀이할 수 있다.
코드
select *
from(
select city, length(city)
from station
order by length(city) asc, city asc
)
where rownum < 2;
select *
from(
select city, length(city)
from station
order by length(city) desc, city desc
)
where rownum < 2;