We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
MS SQL Server:
I think below code is easy to understand and works well in MS SQL Server:
WITH shortest as
(
select top 1 city, len(city) as small_city from station
order by len(city),city
),
largest as
(
select top 1 city, len(city) as big_city from station
order by len(city) desc,city asc
)
select city, small_city from shortest
union all
select city, big_city from largest;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 5
You are viewing a single comment's thread. Return to all comments →
MS SQL Server: I think below code is easy to understand and works well in MS SQL Server:
WITH shortest as ( select top 1 city, len(city) as small_city from station order by len(city),city ), largest as ( select top 1 city, len(city) as big_city from station order by len(city) desc,city asc ) select city, small_city from shortest union all select city, big_city from largest;