공부/PS ( SQL)

[HackerRank/Basic Select] Weather Observation Station 5

happyst 2022. 5. 15. 23:11

https://www.hackerrank.com/challenges/weather-observation-station-5/problem 

 

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

문제

풀이

 

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

 

  • 세미콜론(;) : 쿼리문을 연결해주는 역할
  • ORDER BY A (ASC/DESC) , B (ASC/DESC) : 먼저 A 컬럼에 대해 정렬 후 B 컬럼에 대해 정렬함