32 lines
839 B
SQL
32 lines
839 B
SQL
CREATE OR REPLACE VIEW month_artists AS
|
|
SELECT
|
|
ol.artist_name,
|
|
COUNT(*) AS plays,
|
|
ol.artist_art,
|
|
ol.artist_url,
|
|
ARRAY_AGG(DISTINCT ol.genre_name) AS genres,
|
|
json_build_object(
|
|
'title', ol.artist_name,
|
|
'image', ol.artist_art,
|
|
'url', ol.artist_url,
|
|
'alt', CONCAT(COUNT(*), ' plays of ', ol.artist_name),
|
|
'subtext', CONCAT(COUNT(*), ' plays')
|
|
) AS grid,
|
|
json_build_object(
|
|
'open_graph_image',
|
|
CASE
|
|
WHEN ol.opengraph_image_artist IS NOT NULL AND ol.opengraph_image_artist != '' AND ol.opengraph_image_artist != '/' THEN ol.opengraph_image_artist
|
|
ELSE NULL
|
|
END
|
|
) AS metadata
|
|
FROM
|
|
optimized_listens ol
|
|
WHERE
|
|
TO_TIMESTAMP(ol.listened_at) >= NOW() - INTERVAL '30 days'
|
|
GROUP BY
|
|
ol.artist_name,
|
|
ol.artist_art,
|
|
ol.artist_url,
|
|
ol.opengraph_image_artist
|
|
ORDER BY
|
|
plays DESC;
|