SQL 문제풀이
leetcode - 197. Rising Temperature
Jerrytwo
2022. 6. 30. 16:59
난이도 : Easy
Table: Weather
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| recordDate | date |
| temperature | int |
+---------------+---------+
id is the primary key for this table.
This table contains information about the temperature on a certain day.
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.
join을 활용한 방법
SELECT w2.id
FROM Weather w1
JOIN Weather w2 ON w1.recordDate = DATE_SUB(w2.recordDate, INTERVAL 1 DAY)
WHERE w1.temperature < w2.temperature
Accepted
테이블 2개를 from절로 가져오는 방법
SELECT w2.id
FROM Weather w1
,Weather w2
WHERE w1.temperature < w2.temperature
AND DATEDIFF(w2.recordDate, w1.recordDAte) = 1
Accepted