-
leetcode - 197. Rising TemperatureSQL 문제풀이 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
'SQL 문제풀이' 카테고리의 다른 글
leetcode - 512. Game Play Analysis II (0) 2022.06.30 leetcode - 511. Game Play Analysis I (0) 2022.06.30 leetcode - 196. Delete Duplicate Emails (0) 2022.06.30 leetcode - 574. Winning Candidate (0) 2022.06.29 leetcode - 570. Managers with at Least 5 Direct Reports (0) 2022.06.29