https://leetcode.com/problems/rising-temperature/
Write an SQL query to find all dates' Id with higher temperatures compared to its previous dates (yesterday).
Return the result table in any order.
The query result format is in the following example.
Output:
+----+
| id |
+----+
| 2 |
| 4 |
+----+
조회할 데이터 : 전 날보다 기온이 높은 날들의 id
SELECT Today.id
FROM weather AS Today
LEFT JOIN weather AS Yesterday ON Today.recorddate = DATE_ADD(Yesterday.recorddate, INTERVAL 1 DAY)
WHERE Today.temperature > Yesterday.temperature
- mySQL에서 시간 더하기, 빼기 DATE_ADD, DATE_SUB
DATE_ADD(기준, INTERVAL ~ SECOND)
DATE_SUB(기준, INTERVAL ~ SECOND)
SECOND 대신 MINUTE, HOUR, DAY, YEAR 모두 가능하다
- DATE_ADD(기준, INTERVAL ~ - YEAR)
= DATE_SUB(기준, INTERVAL ~ YEAR)