Im between cherry

Hackerrank | MySQL | Weather Observation Station 5 본문

데이터분석/practice_query

Hackerrank | MySQL | Weather Observation Station 5

meal 2020. 8. 27. 18:16

Weather Observation Station 5

Problem

 

Weather Observation Station 5 | HackerRank

Write a query to print the shortest and longest length city name along with the length of the city names.

www.hackerrank.com

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.
The STATION table is described as follows:

 

 

 

Solution

(SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) ASC, CITY
LIMIT 1)
UNION
(SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) DESC, CITY
LIMIT 1)

 

Comments