관리 메뉴

오늘도 배운다

Weather Observation Station 5 / Hacker Rank, SQL, MySQL 본문

코딩테스트연습(SQL)

Weather Observation Station 5 / Hacker Rank, SQL, MySQL

LearnerToRunner 2022. 11. 30. 10:54

문제

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:

 

제출답안(MySQL)

(SELECT city, LENGTH(city) FROM station ORDER BY 2 DESC, 1 LIMIT 1)
UNION
(SELECT city, LENGTH(city) FROM station ORDER BY 2, 1 LIMIT 1)

 

문제 바로가기(MySQL) 

 

728x90
Comments