728x90
문제
https://leetcode.com/problems/rising-temperature/description/
풀이
이전 날짜보다 현재 날짜의 temperature 가 더 높아진 행의 id 를 출력하는 문제다.
결과에는 id만 나와야 하므로, LAG 대신 조건을 만족하는 행을 조인해주는 방식으로 해결했다.
또한, 이전 날짜와 현재 날짜의 차이는 하루여야 하므로 DATEDIFF의 결과가 1인 행에 대해서만 계산했다.
SELECT w1.id
FROM Weather w1
JOIN
Weather w2
ON DATEDIFF(w1.recordDate, w2.recordDate) = 1 and w1.temperature > w2.temperature;
소스코드
https://github.com/rogi-rogi/problem-solving/blob/main/leetcode/sql/easy/197-rising-temperature.sql
728x90
'PS' 카테고리의 다른 글
[Programmers 알고리즘 고득점 Kit] 여행 경로[Python] (0) | 2025.02.28 |
---|---|
[Programmers 알고리즘 고득점 Kit] 네트워크 [Python] (0) | 2025.02.26 |
[프로그래머스] 카펫 [Java] (0) | 2025.02.21 |
[프로그래머스] 등굣길 [Java] (0) | 2025.02.01 |
코딩테스트에 대하여... (4) | 2024.11.22 |