From 714a5de10f292084d7b5577fbc221e82621426b6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 27 Jul 2018 19:50:54 +0200 Subject: [PATCH] wow --- wow.sql | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 wow.sql diff --git a/wow.sql b/wow.sql new file mode 100644 index 00000000..f2e51aca --- /dev/null +++ b/wow.sql @@ -0,0 +1,34 @@ +SELECT * +FROM discord +LEFT JOIN ( + SELECT DISTINCT ON (ma.discord_id) + ma.discord_id discord_id2, + fs.fav_song fav_song2, + ma.max_plays max_plays2 + FROM ( + SELECT + discord_id, + max(plays) max_plays + FROM + ( + SELECT + playedmusic.enqueuer_id discord_id, + playedmusic.filename fav_song, + count(*) plays + FROM playedmusic + GROUP BY playedmusic.filename, playedmusic.enqueuer_id + ORDER BY plays DESC + ) play_counts + GROUP BY discord_id + ) ma + INNER JOIN + ( + SELECT + playedmusic.enqueuer_id discord_id, + playedmusic.filename fav_song, + count(*) plays + FROM playedmusic + GROUP BY playedmusic.filename, playedmusic.enqueuer_id + ORDER BY plays DESC + ) fs ON fs.discord_id = ma.discord_id AND fs.plays = ma.max_plays +) fav_songs ON fav_songs.discord_id2 = discord.discord_id; \ No newline at end of file