GULGUL CODING
Weather Observation Station 5 본문
Weather Observation Station 5
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. |
정답)
SELECT city
,length
FROM (SELECT city
,LENGTH(city) length
,ROW_NUMBER() OVER(ORDER BY LENGTH(city) DESC ,city ASC ) L
,ROW_NUMBER() OVER(ORDER BY LENGTH(city) ASC ,city ASC ) S
FROM station )
WHERE L = 1 OR S =1 ;
서브쿼리를 써야겠다는 생각과 ROWNUM을 써봐야겠다는 생각은 했는데 뭔가 이상해서
RANK함수를 쓰고싶었는데 혼돈의 카오스..ㅋㅋㅋ뭔가 어렵다.. EASY 난이도인데..열심히 해야지 😂
*ROW_NUMBER() : ORDER BY 된 결과에 순번을 매기고 싶을때 사용한다
ROW_NUMBER() OVER(ORDER BY 정렬칼럼)
'코딩테스트 > hackerrank' 카테고리의 다른 글
Symmetric Pairs (0) | 2023.07.23 |
---|
Comments