# Pastebin jyqqYaQx WITH temp( SELECT explode(mb_artist_credit_mbids) as artist_mbid, user_name FROM listens ) SELECT artist_mbid, user_name, count(artist_mbid) as listen_count, dense_rank() over(order by artist_mbid) as artist_id, dense_rank() over(order by user_name) as user_id FROM temp GROUP BY artist_mbid, user_name;