문제 URL : 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
문제 : city 이름중에 가장긴이름과 가장작은이름 을찾으면서 동시에 그 길이를 출력하라는겁니다.
각각 한개씩 출력하기때문에
이문제 좀 고민을 좀했어야했습니다.
max나 min을 이용하는줄알았는데 order by를 이용해서 limit를 이용하면 바로찾을수있습니다.
(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)
'HackerRank' 카테고리의 다른 글
해커랭크 The PADS (0) | 2022.12.15 |
---|---|
해커랭크 Top Earners (0) | 2022.12.15 |
해커랭크 Weather Observation Station 6 ->MySql (0) | 2022.11.30 |