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.
WITH cte AS (
SELECT
city,
LENGTH(city) AS city_length,
ROW_NUMBER() OVER (ORDER BY LENGTH(city), city) AS rank_min,
ROW_NUMBER() OVER (ORDER BY LENGTH(city) DESC, city DESC) AS rank_max
FROM station
)
SELECT city, city_length FROM cte WHERE rank_min = 1
UNION
SELECT city, city_length FROM cte WHERE rank_max = 1;
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 →
WITH cte AS ( SELECT city, LENGTH(city) AS city_length, ROW_NUMBER() OVER (ORDER BY LENGTH(city), city) AS rank_min, ROW_NUMBER() OVER (ORDER BY LENGTH(city) DESC, city DESC) AS rank_max FROM station ) SELECT city, city_length FROM cte WHERE rank_min = 1 UNION SELECT city, city_length FROM cte WHERE rank_max = 1;