728x90
728x90
Problem
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.
-> station에서 가장 짧고 긴 도시 이름과 각각의 길이를 출력하시오. 가장 작은 도시 또는 가장 큰 도시가 두 개 이상 있는 경우, 알파벳 순으로 정렬하시오.
Answer
select city, length(city)
from station
order by length(city),city limit 1;
select city, length(city)
from station
order by length(city) desc,city limit 1
728x90
728x90
'Language > SQL' 카테고리의 다른 글
[HackerRank][SQL] Weather Observation Station 7 - 컴도리돌이 (0) | 2022.05.18 |
---|---|
[HackerRank][SQL] Weather Observation Station 6 - 컴도리돌이 (0) | 2022.05.18 |
[HackerRank][SQL] Weather Observation Station 4 - 컴도리돌이 (0) | 2022.05.18 |
[HackerRank][SQL] Weather Observation Station 3 - 컴도리돌이 (0) | 2022.05.18 |
[HackerRank][SQL] Weather Observation Station 2 - 컴도리돌이 (0) | 2022.05.18 |