Skip to content

Instantly share code, notes, and snippets.

@mlivingston40
Last active March 29, 2024 17:11
Show Gist options
  • Save mlivingston40/296095d2223b80ccd4536fbd9a52e799 to your computer and use it in GitHub Desktop.
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).
-- 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