[해커랭크] Weather Observation Station 5

june510·2023년 3월 19일
0

SQL

목록 보기
3/10

MySQL

⭐ Weather Observation Station 5

https://www.hackerrank.com/challenges/weather-observation-station-5

  • 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.
(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)

Amo 3
Marine On Saint Croix 21

Lesson & Learned

shortest 와 longest CITY name을 동시에 조회할 수 없다.
아래 코드에 UNION() 연산을 추가해서 두 SELECT절을 위, 아래로 결합했다.

SELECT city, LENGTH(city)
FROM station
ORDER BY LENGTH(city), city
profile
나의 계절은

0개의 댓글