Created
April 24, 2023 23:02
-
-
Save rorymalcolm/8bb9b59c777f97aa4b941710d7450caa 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
CREATE OR REPLACE VIEW | |
listening_history_cleaned AS | |
SELECT | |
master_metadata_album_artist_name as artist, | |
master_metadata_track_name as track, | |
ms_played as play_time_ms, | |
ms_played / 1000 / 60 AS play_time_m, | |
conn_country as country_listened_from, | |
ip_addr_decrypted as ip_address, | |
strptime (ts, '%Y-%m-%dT%H:%M:%SZ') as timestamp, | |
CASE | |
WHEN offline_timestamp IS NOT NULL | |
AND offline_timestamp != 0 THEN to_timestamp(offline_timestamp) | |
ELSE NULL | |
END as offline_timestamp, | |
episode_name as episode, | |
episode_show_name as show, | |
reason_start as reason_start, | |
reason_end as reason_end, | |
shuffle as is_shuffle, | |
CASE | |
WHEN skipped = true THEN true | |
ELSE false | |
END as is_skipped, | |
offline as is_offline, | |
incognito_mode as is_incognito, | |
datediff( | |
'year', | |
strptime ('-INSERT BIRTHDAY HERE-', '%Y-%m-%d'), | |
strptime (ts, '%Y-%m-%dT%H:%M:%SZ') | |
) as age_at_listen | |
FROM | |
listening_history | |
WHERE | |
master_metadata_album_artist_name IS NOT NULL | |
AND master_metadata_album_artist_name != '' | |
AND master_metadata_track_name IS NOT NULL | |
AND master_metadata_track_name != ''; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment