일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 빅데이터
- 당신이 몰랐던 진화론
- Great Minds
- 미분적분학
- 데이터분석전문가가이드
- 위대한 수업
- 백준
- CNN10
- ADsP
- python
- Baekjoon
- 맛집
- K-MOOC
- 후기
- 자료구조
- 알고리즘
- 코테
- 조지프 나이
- Hacker Rank
- 공부정리
- Udemy
- Joseph Samuel Nye Jr.
- MySQL
- 누가 진정한 리더인가
- 데이터분석전문가
- EBS
- 정치학
- ADP
- Progate
- KMOOC
- Today
- Total
ㅇ
[Hacker Rank_MySQL]문제 풀이#Weather Observation Station 5 본문
SQL > Basic Select > Weather Observation Station 5
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.
Note
You can write two separate queries to get the desired output. It need not be a single query.
빨간 글씨는 내가 문제를 풀 때 중요하다고 생각한 부분이다.
도시 이름의 길이가 가장 짧은 것과 가장 긴 것의 도시 이름과 그 길이를 가져오라고 하는데, 만약 길이가 동일한 도시가 여러개 있을 경우에는 알파벳순으로 가장 먼저 오는 것을 고르라고 한다. 또한 문제에서 쿼리를 2개 써야 원하는 것을 얻을 수 있다고 알려주었다.
/*
USING LIMIT 1
*/
SELECT *
FROM (
SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) ASC, CITY ASC
LIMIT 1
) X
UNION
SELECT *
FROM (
SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) DESC, CITY ASC
LIMIT 1
) Y
'IT > 코테문제' 카테고리의 다른 글
[Hacker Rank_MySQL]문제 풀이#Top Earners (0) | 2022.02.28 |
---|---|
[Hacker Rank_MySQL]문제 풀이#Ollivander's Inventory (0) | 2022.02.27 |
[Hacker Rank_MySQL]문제 풀이#Top Competitors (0) | 2022.02.27 |
[Hacker Rank_MySQL]문제 풀이#The Report (0) | 2022.02.23 |
[Hacker Rank_MySQL]문제 풀이#Higher Than 75 Marks (0) | 2022.02.21 |