SQL
Hackers Rank : SQL Oracle : Weather Observation Station 5 solution
devorldist
2022. 6. 1. 17:15
728x90
반응형
SMALL
# Q
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.
# A
SELECT CITY, LENGTH(CITY)
FROM (SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY), CITY)
WHERE ROWNUM=1;
SELECT CITY, LENGTH(CITY)
FROM (SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) DESC, CITY)
WHERE ROWNUM=1;
728x90
반응형
LIST