Last active
March 29, 2024 17:11
-
-
Save mlivingston40/296095d2223b80ccd4536fbd9a52e799 to your computer and use it in GitHub Desktop.
Write a solution to find all dates' Id with higher temperatures compared to its previous dates (yesterday).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Write your PostgreSQL query statement below | |
select | |
id as Id | |
from | |
( | |
select | |
id, | |
recordDate, | |
temperature, | |
LAG(temperature, 1) OVER ( | |
ORDER BY recordDate asc | |
) as last_date_temp, | |
LAG(recordDate, 1) OVER ( | |
ORDER BY recordDate asc | |
) as last_date | |
from Weather | |
) | |
where (temperature - last_date_temp) > 0 | |
and (recordDate - last_date) = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment