HACKERRANK PRACTICE SQL@Weather Observation Station 5
PROBLEM
Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.
GOOGLE 翻译:
使用最短和最长的CITY名称查询STATION中的两个城市,以及它们各自的长度(即:名称中的字符数)。 如果有多个最小或最大的城市,请选择按字母顺序排序的城市。
Input Format
The STATION table is described as follows:
MY ANSWER
(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY),CITY LIMIT 1)
UNION
(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY LIMIT 1)