coryd.dev/queries/selects/top-artists.psql

13 lines
292 B
Text

SELECT
l.artist_name,
TO_CHAR(COUNT(l.id), 'FM999,999,999') AS total_listens
FROM
optimized_listens l
WHERE
EXTRACT(YEAR FROM TO_TIMESTAMP(l.listened_at)) = EXTRACT(YEAR FROM CURRENT_DATE)
AND l.artist_name IS NOT NULL
GROUP BY
l.artist_name
ORDER BY
COUNT(l.id) DESC
LIMIT 10;