프로그래밍연습/SQL

[SQL]weather-observation-station-5

Q_jihe 2023. 8. 25. 14:26

https://www.hackerrank.com/challenges/weather-observation-station-5

 

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

with base as (
select
    city, length(city) len
    , dense_rank() over (order by length(city), city) rn1
    , dense_rank() over (order by length(city) desc, city) rn2  
from station
)
select
    distinct city, len
from base
where rn1 = 1 or rn2 = 1