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.
Weather Observation Station 5
Weather Observation Station 5
Sort by
recency
|
7089 Discussions
|
Please Login in order to post a comment
this my solution with MsSQL server
select distinct top 1 city , len(city) from station where len(city) < (select max(len(city)) from station) order by len(city)
select distinct top 1 city , len(city) from station where len(city) > (select min(len(city)) from station) order by len(city) desc
working code SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY), CITY LIMIT 1;
SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY LIMIT 1;
SELECT CITY,LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) ASC, CITY ASC LIMIT 1; SELECT CITY,LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY ASC LIMIT 1;
-- create city, number of length WITH city_lengths AS ( SELECT CITY, CHAR_LENGTH(CITY) AS len FROM STATION ), -- set first condition with the longest_city longest_city AS ( SELECT CITY, len FROM city_lengths WHERE len = (SELECT MAX(len) FROM city_lengths) ORDER BY CITY ASC LIMIT 1 ), -- set second condition with the shortest_city shortest_city AS ( SELECT CITY, len FROM city_lengths WHERE len = (SELECT MIN(len) FROM city_lengths) ORDER BY CITY ASC LIMIT 1 ) -- combine them together SELECT * FROM longest_city UNION SELECT * FROM shortest_city;
-- Shortest CITY name SELECT TOP 1 CITY, LEN(CITY) AS LEN FROM ( SELECT CITY FROM STATION ) AS Shortest ORDER BY LEN(CITY) ASC, CITY ASC;
-- Longest CITY name SELECT TOP 1 CITY, LEN(CITY) AS LEN FROM ( SELECT CITY FROM STATION ) AS Longest ORDER BY LEN(CITY) DESC, CITY ASC;