Last active
February 20, 2022 13:01
-
-
Save James-McNeill/4722c8bb7b685f13ae76c7fac81c338a to your computer and use it in GitHub Desktop.
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
-- Time Series functions | |
SELECT *, | |
AVG(t1.Value) | |
OVER( | |
PARTITION BY t1.Area, t1.Property_type | |
ORDER BY t1.Date | |
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW | |
) sma3, | |
LAG(t1.Value, 3, 0) | |
OVER( | |
PARTITION BY t1.Area, t1.Property_type | |
ORDER BY t1.Date | |
) lagValue3, | |
(t1.Value / | |
LAG(t1.Value, 3) | |
OVER( | |
PARTITION BY t1.Area, t1.Property_type | |
ORDER BY t1.Date | |
) | |
) - 1 AS pctChange3m | |
FROM Medium.dbo.HPM09_202112 AS t1 | |
WHERE t1.Value > 0 | |
AND t1.Date BETWEEN '2020-01-01' AND '2020-06-01' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment