# Pastebin zrrbuMbd SELECT * FROM ( 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, sum(count(artist_mbid)) over(partition by user_name) as total_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 ) WHERE total_count > {threshold};