Snoopy [해커랭크/SQL] 10. Weather Observation Station 5
코딩테스트/해커랭크 SQL

[해커랭크/SQL] 10. Weather Observation Station 5

Sooyoon Jeong 2023. 2. 15.

👉 https://www.hackerrank.com/challenges/weather-observation-station-5/problem?isFullScreen=true

 

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


🤔 문제 분석

1) 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)

 

댓글