자료구조 알고리즘/코딩테스트
197. Rising Temperature
내공얌냠
2022. 6. 3. 13:39
https://leetcode.com/problems/rising-temperature/
Rising Temperature - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
select a.id as Id
from Weather as a
join Weather as b
on DATEDIFF(a.recordDate, b.recordDate) = 1 and a.temperature > b.temperature
solution comment 에는 id 를 가지고 하는 것도 있었다.
어제 오늘의 경우 id가 하나 차이가 나니까.
solution에 나오기로는 join 과 datediff 를 사용하는 것이 핵심이라고 한다.
나는 datediff 를 모르고 +1 연산으로만 했었는데 이 방법은 mysql에서는 안 된다고 한다.
그리고 datediff(내일, 오늘) = 1 이런 식으로 해야 양수로 나온다. 앞의 인자가 더 뒤의 날짜로.
best
SELECT w2.Id FROM Weather w1,Weather w2
WHERE w2.recordDate = DATE_ADD(w1.recordDate, INTERVAL 1 DAY)
AND w2.Temperature > w1.Temperature;
728x90
반응형