https://www.hackerrank.com/challenges/weather-observation-station-5/problem?isFullScreen=true
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;
|
cs |
Question:
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:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Sample Input
For example, CITY has four entries: DEF, ABC, PQRS and WXY.
Sample Output
ABC 3
PQRS 4
풀이:
길이 기준으로 정렬 후, 알파벳순으로 도시를 나열하여 하나 출력합니다
그리고 마찬가지의 방법으로 도시를 역순으로 나열하여 하나 출력합니다
'HackerRank' 카테고리의 다른 글
[StrataScratch] Salaries Differences [MySQL] (0) | 2022.06.22 |
---|---|
[StrataScratch] Workers With The Highest Salaries - 최대 값 찾기 [MySQL] (0) | 2022.06.22 |
[HackerRank Medium] Symmetric Pairs [MySQL] (0) | 2022.05.26 |
[MySQL] The Report [HackerRank Medium] (0) | 2022.05.26 |
[MySQL] Binary Tree Nodes [HackerRank Medium] (0) | 2022.05.26 |