일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- SQL 날짜 데이터
- leetcode
- Window Function
- SQL코테
- 설명의무
- 그룹바이
- update
- 짝수
- LSTM
- airflow
- Statistics
- 논문리뷰
- 표준편차
- inner join
- 카이제곱분포
- sql
- 서브쿼리
- nlp논문
- MySQL
- torch
- 자연어 논문
- HackerRank
- CASE
- 코딩테스트
- sigmoid
- 자연어처리
- GRU
- 자연어 논문 리뷰
- t분포
- NLP
- Today
- Total
HAZEL
[ SQL : LENGTH ] hackerrank : Weather Observation Station 5 본문
[ SQL : LENGTH ] hackerrank : Weather Observation Station 5
Rmsid01 2021. 10. 25. 20:24Weather 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.
The STATION table is described as follows:
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
where id = (select id
from station
order by LENGTH(city), city
limit 1)
or id = (
select id
from station
order by LENGTH(city) desc , city
limit 1
)
사용된 개념 : LENGTH
* LENGTH() : BYTE 수를 기준으로 문자열의 길이를 출력합니다.
* CHAR_LENGTH() : 글자 수를 기준으로 문자열의 길이를 출력합니다.
https://www.hackerrank.com/challenges/weather-observation-station-5/problem
'DATA ANALYSIS > SQL' 카테고리의 다른 글
[서브쿼리] hackerrank : Weather Observation Station 17 (0) | 2021.11.15 |
---|---|
[ SQL : 사용자 정의 함수(DECLARE, SET), CASE , IF, LIMIT 심화 ] 177. Nth Highest Salary (0) | 2021.11.12 |
[ SQL : 날짜 빼기, TIMESTAMPDIFF, DATEDIFF] 프로그래머스 오랜 기간 보호한 동물(2) (0) | 2021.10.16 |
[ SQL : 사용자 정의 함수, User - defined Function ] (0) | 2021.05.17 |
[SQL : 정규표현식 ] HackerRank : Weather Observation Station 7 / 8 (0) | 2021.05.16 |