TECH

Weather Observation Station 5

AKA.DM 2022. 6. 9. 13:01
반응형

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:

 

select city, length(city)
from (
        select city, length(city) from station 
        order by length(city) asc, city asc
      )
where 
    rownum = 1 ;
    
select city, length(city)
from (
        select city, length(city) from station 
        order by length(city) desc, city asc
      )
where 
    rownum = 1 ;

SQL 기초 지식이 없어서 몇날 몇일 걸렸다.

 

아직도 order by 구절과 rownum 구절 사용법에 대해서는 모르겠다.

 

하지만 답은 맞음...

 

반응형