[LeetCode] 197. Rising Temperature

2022. 6. 9. 22:23SQL

내 첫 쿼리

SELECT id
FROM (SELECT id
            ,recorddate
            ,temperature
            ,(LAG(temperature) OVER (ORDER BY id)) AS tem2
      FROM weather) sub
WHERE (temperature-tem2)>0

완성 쿼리 

SELECT w.id
FROM weather w
JOIN weather w1
ON DATEDIFF(w.recordDate,w1.recordDate) = 1
AND w.temperature > w1.temperature

조인 조건 ON에 DATEDIFF 함수 사용 가능