Created
January 31, 2012 17:22
-
-
Save chanmix51/1711698 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ALTER TABLE city ADD COLUMN last_weather_data weather_probe; | |
UPDATE | |
city c | |
SET | |
last_weather = wp | |
FROM | |
( | |
SELECT | |
wp.city_name, | |
wp.created_at, | |
rank() OVER created_at_window AS ranking | |
FROM | |
weather_probe wp | |
WINDOW | |
created_at_window AS (PARTITION BY city_name ORDER BY created_at DESC) | |
) wpr | |
NATURAL JOIN weather_probe wp | |
WHERE | |
wpr.ranking = 1 | |
AND | |
c.name = wp.city_name | |
RETURNING * | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment