Created
July 25, 2022 18:36
-
-
Save thomasthaddeus/6d51615993e2abeae6e580214e8685db to your computer and use it in GitHub Desktop.
Window Functions in SQL
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
SELECT | |
artist, | |
week, | |
streams_millions, | |
streams_millions - LAG(streams_millions, 1, streams_millions) OVER ( | |
PARTITION BY artist | |
ORDER BY week | |
) AS 'streams_millions_change', | |
chart_position, | |
LAG(chart_position, 1, chart_position) OVER ( | |
PARTITION BY artist | |
ORDER BY week | |
) - chart_position AS 'chart_position_change' | |
FROM | |
streams | |
WHERE | |
artist = 'Lady Gaga'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment