문제

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.

When ordered alphabetically, the CITY names are listed as ABC, DEF, PQRS, and WXY, with lengths 3, 3, 4 and 3. The longest name is PQRS, but there are 3 options for shortest named city. Choose ABC, because it comes first alphabetically.

 

 

 

city 이름 길이가 가장 짧은 도시, 가장 긴 도시를 출력하는 문제

limit을 사용하면 쉽게 구할 수 있다.

 

 

풀이 코드

order by를 사용해서 도시 이름 길이에 따라 오름차순, 내림차순으로 각각 나열한 후 limit 1을 걸어주면 가장 짧은 길이의 이름을 가진 도시와 가장 긴 길이의 이름을 가진 도시가 출력된다.

+ Recent posts