조컴퓨터

hackerrank Weather Observation Station 5 본문

HackerRank/SQL

hackerrank Weather Observation Station 5

챠오위 2021. 1. 31. 00:05

 

 

1) 짧은 도시명

 

1-1)

SELECT city, LENGTH(city)

FROM STATION

ORDER BY LENGTH(city), city;

 

1-1) 결과

 

 

1-2) 

SELECT * 

FROM (

       SELECT city, LENGTH(city)

       FROM STATION

       ORDER BY LENGTH(city), city

)

WHERE rownum = 1;

 

1-2) 결과

 

 

2) 가장 긴 도시명

 

2-1)

SELECT city, LENGTH(city)

FROM STATION
ORDER BY LENGTH(city) DESC, city DESC;

 

2-1) 결과

 

 

2-2)

SELECT *

FROM (

       SELECT city, LENGTH(city)

       FROM STATION

       ORDER BY LENGTH(city) DESC, city DESC

)

WHERE rownum = 1; 

 

2-2) 결과

 

 

3) UNION

SELECT *

FROM (

       SELECT city, LENGTH(city)

       FROM STATION

       ORDER BY LENGTH(city), city

)

WHERE rownum = 1

UNION

SELECT *

FROM (

       SELECT city, LENGTH(city)

       FROM STATION

       ORDER BY LENGTH(city) DESC, city DESC

)

WHERE rownum = 1; 

 

3) 결과

 

 

SUCCESS!!

 

 

 

 

 

'HackerRank > SQL' 카테고리의 다른 글

hackerrank Draw The Triangle 2  (0) 2021.02.18
hackerrank Weather Observation Station 6  (0) 2021.01.31
hackerrank Weather Observation Station 3  (0) 2021.01.30
hackerrank Symmetric Pairs  (0) 2021.01.18
hackerrank Type of Triangle  (0) 2021.01.18