728x90
www.hackerrank.com/challenges/weather-observation-station-5/problem?h_r=next-challenge&h_v=zen
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
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.
CITY의 데이터 중 가장 짧은 도시 이름과, 가장 긴 도시 이름을 출력한다. 만약 길이가 같을 경우 알파벳 순으로 출력한다. + 쿼리를 두 개 사용해도 된다.
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;
LENGTH('내용')을 통해서 글자 수를 계산했고, 정렬을 글자 수와 알파벳으로 정렬했다.
최상위 한 개를 출력하기 위해 LIMIT 구문을 이용했다.
728x90
'문제 풀이 > Hackerrank SQL' 카테고리의 다른 글
[Hackerrank SQL] Average Population of Each Continent (0) | 2021.02.24 |
---|---|
[Hackerrank SQL] Type of Triangle (0) | 2021.02.24 |
[Hackerrank SQL] Weather Observation Station 13 (0) | 2021.02.23 |
[Hackerrank SQL] Weather Observation Station 8 (0) | 2021.02.23 |
[Hackerrank SQL] Weather Observation Station 3 (0) | 2021.02.20 |