https://leetcode.com/problems/rising-temperature/description/?envType=study-plan-v2&envId=top-sql-50
recordDate를 기준으로 JOIN
(a가 previous day가 되도록)
SELECT b.Id
FROM weather a
INNER JOIN weather b ON a.recordDate = b.recordDate - 1 -- a : yesterday
WHERE a.temperature < b.temperature
LEFT JOIN이 아닌 INNER JOIN을 써줘야 연속된 날짜를 구할 수 있다.
DATE 계산을 조금 더 깔끔하게 적으면 이렇게 적을 수도 있다 !
SELECT w2.id
FROM Weather w1
JOIN Weather w2
ON DATEDIFF(w1.recordDate, w2.recordDate) = -1
AND w2.temperature>w1.temperature
'SQL > 문제풀이' 카테고리의 다른 글
[LeetCode] customers-who-bought-all-products (0) | 2024.03.04 |
---|---|
[LeetCode] Product Sales Analysis 3 (0) | 2024.03.04 |
[LeetCode] SQL 50 : Select (0) | 2024.02.26 |
[LeetCode] Department Highest Salary (0) | 2024.02.18 |
[HakcerRank] Top Earners (0) | 2024.02.16 |