Query shortest and longest cities and length from the STATION table by using LENGTH(), ORDER BY, LIMIT. This is the solution of HackerRank's Weather Observation Station 5 SQL problem.
Table name: STATION
Table Structure:
Fileds | Type |
ID | NUMBER |
CITY | VARCHAR |
STATE | VARCHAR |
LAT_N | NUMBER |
LONG_W | NUMBER |
SQL Query:
(SELECT CITY, LENGTH(CITY) AS len
FROM STATION
ORDER BY len ASC, CITY ASC
LIMIT 1)
UNION
(SELECT CITY, LENGTH(CITY) AS len
FROM STATION
ORDER BY len DESC, CITY DESC
LIMIT 1);