일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- dl
- 신경망
- 프로그래머스
- affine
- Programmers
- kakao
- CBOW
- Word2vec
- PPMI
- Sigmoid
- Stack
- SQL
- Numpy
- skip-gram
- 자연어처리
- Python
- sort
- 파이썬
- MySQL
- que
- Heap
- hash
- 딥러닝
- FullyConnectedLayer
- DeepLearning
- boj
- select
- stak
- algorithm
- backward
- Today
- Total
혜온의 이것저것
[HackerRank] Weather Observation Station 5 (MySQL) 본문
https://www.hackerrank.com/challenges/weather-observation-station-5/problem?isFullScreen=true
Weather Observation Station 5 | HackerRank
Write a query to print the shortest and longest length city name along with the length of the city names.
www.hackerrank.com
문제
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:
![](https://blog.kakaocdn.net/dn/djKYX5/btrI7LeCcuA/TgjiYrndKQGhMtcqlKi6eK/img.jpg)
where LAT_N is the northern latitude and LONG_W is the western longitude.
Sample Input
For example, CITY has four entries: DEF, ABC, PQRS and WXY.
Sample Output
ABC 3
PQRS 4
Explanation
When ordered alphabetically, the CITY names are listed as ABC, DEF, PQRS, and WXY, with lengths and . The longest name is PQRS, but there are options for shortest named city. Choose ABC, because it comes first alphabetically.
Note
You can write two separate queries to get the desired output. It need not be a single query.
풀이
select city, length(city)
from station
order by length(city), city
limit 1;
select city, length(city)
from station
order by length(city) desc, city asc
limit 1;
'Data Analysis > SQL' 카테고리의 다른 글
[HackerRank] Weather Obsercation Station 7 (MySQL) (0) | 2022.08.08 |
---|---|
[HackerRank] Weather Observation Station 6 (MySQL) (0) | 2022.08.08 |
[HackerRank] Weather Observation Station 4 (MySQL) (0) | 2022.08.08 |
[HackerRank] Weather Observation Station 3 (MySQL) (0) | 2022.08.03 |
[HackerRank] Weather Observation Station 1 (MySQL) (0) | 2022.08.03 |