-
-
Save rorymalcolm/2eb95daddc089cd3dd8c015f9de50d32 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
with | |
age_count_per_track as ( | |
select | |
age_at_listen, | |
artist, | |
track, | |
sum(play_time_ms) as sum | |
from | |
listening_history_cleaned | |
group by | |
1, | |
2, | |
3 | |
), | |
top_song_per_age as ( | |
select | |
age_at_listen, | |
artist, | |
track, | |
sum, | |
row_number() over ( | |
partition by | |
age_at_listen | |
order by | |
sum desc | |
) as rank | |
from | |
age_count_per_track | |
) | |
select | |
* | |
from | |
top_song_per_age | |
where | |
rank = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment