문제
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:
코드
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;
- STATION 테이블에서 city이름의 길이가 가장 짧은 컬럼과 가장 긴 컬럼을 출력 > length() 이용
- 길이가 가장 짧은 도시와 긴 도시가 둘 이상인 경우 알파벳순으로 정렬
출처
반응형
'Algorithm > MySQL' 카테고리의 다른 글
[해커랭크(HackerRank)] Weather Observation Station 8 (MySQL) (0) | 2021.07.04 |
---|---|
[해커랭크(HackerRank)] Weather Observation Station 7 (MySQL) (0) | 2021.07.04 |
[해커랭크(HackerRank)] Japanese Cities' Names (MySQL) (0) | 2021.07.04 |
[해커랭크(HackerRank)] Japanese Cities' Attributes (MySQL) (0) | 2021.07.04 |
[프로그래머스] 오랜 기간 보호한 동물(2) (MySQL) (0) | 2021.07.02 |