Notice
Recent Posts
Recent Comments
250x250
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- python
- merge
- dateofmonth
- 레이더차트
- 모집단
- limit
- 재퀴쿼리
- join
- lambda
- Recursive
- tableau
- 태블로
- 재귀쿼리
- 신뢰구간
- 데이터 리터러시
- pivot table
- 표분편차
- 표준오차
- curdate
- rrule
- floor
- split
- DATE_FORMAT
- truncate
- calesce
- 프로그래머스
- 정규분포
- concat
- 표본분포
- datediff
Archives
- Today
- Total
반응형
hyezdata 님의 블로그
Rising Temperature 본문
# 전날에 비해 높은 온도인 날 id 출력
select w1.id as Id
from weather w1
join weather w2
on datediff(w1.recordDate, w2.recordDate) = 1
where w1.temperature > w2.temperature
첫번째 답
# 전날에 비해 높은 온도인 날 id 출력
select id as Id
from (
select id, temperature, lag(temperature, 1) over (order by recordDate) as before_temp
from Weather
) a
where temperature >= before_temp
-> 이전 행이 반드시 전날일거라는 가능성 없을 수도 있음
-> 그래서 lag 쓰면 안됨 쓰면 안됨이 아니라 이렇게 쓰면 안됨

만약 lag를 쓰고 싶다면
(다른 사람 쿼리)
select id
from (select *,
lag(temperature) over(order by recordDate) as prrev,
lag(recordDate) over(order by recordDate) as prev_date
from Weather) p
where temperature>p.prrev and datediff(recordDate,prev_date)=1
Rising Temperature - LeetCode
Can you solve this real interview question? Rising Temperature - Table: Weather +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | recordDate | date | | temperature | int | +---------------+---------+ id is the co
leetcode.com
728x90
반응형
'코딩테스트' 카테고리의 다른 글
| Trips and Users (0) | 2026.05.11 |
|---|---|
| Game Play Analysis I (0) | 2026.05.07 |
| Delete Duplicate Emails (0) | 2026.05.06 |
| Department Top Three Salaries (0) | 2026.05.06 |
| Department Highest Salary (0) | 2026.05.06 |