Weather Observation Station 5

  • + 0 comments

    First I selected the cities and ranked them basing on their length. Then i filtered min or max lengths. Finaly wraped the query in a CTE and filtered the first row of every rank.

    WITH cte_cities AS ( SELECT city , LEN(city) as citylength , ROW_NUMBER() OVER(PARTITION BY LEN(city) ORDER BY city) as cityorder FROM station WHERE LEN(city) = (SELECT MIN(LEN(city)) FROM station) OR LEN(city) = (SELECT MAX(LEN(city)) FROM station) ) select city, citylength from cte_twocities where cityorder=1 order by citylength, city asc