[LeetCode] 197. Rising Temperature

송범·2025년 1월 24일

문제 링크

https://leetcode.com/problems/rising-temperature/description/

  • 이전 날짜보다 더 높은 기온을 가지는 아이디를 출력해야합니다.
SELECT w1.id as Id
FROM Weather w1 , Weather w2
where w1.temperature > w2.temperature
and  DATEDIFF(w1.recordDate, w2.recordDate) = 1

DATEDIFF 를 사용해서 self join으로 날짜의 차이를 구했습니다.

SELECT today.id as Id
FROM Weather AS today
    INNER JOIN Weather AS yesterday on DATE_ADD(yesterday.recordDate, INTERVAL 1 DAY) = today.recordDate
WHERE today.temperature > yesterday.temperature;

MYSQL 시간 더하기, 빼기

-> DATE_ADD, DATE_SUB 사용 (기준날짜, INTERVAL)

profile
BackEnd&Data Scientist가 되고 싶은 개발 기록 노트

0개의 댓글