Album
Title Artist Year Type Rating
My World Justin Bieber 2009 STUDIO 4
My Worlds: The Collection Justin Bieber 2010 COMPILATION 4
21 Adele 2011 STUDIO 5
Adele Live at the Royal Albert Hall Adele 2011 LIVE 4
Get to Heaven Everything Everything 2015 STUDIO 5
One of the boys Katy Perry 2008 STUDIO 3
Overexposed Maroon 5 2012 STUDIO 5
Live From Le Cabaret: In Montreal. Quebec Maroon 5 2008 LIVE 4
Pure Heroine Lorde 2013 STUDIO 4
因此,在专辑上方,我该如何获得每个艺术家自己的最高评价专辑?
提前致谢。
最佳答案
这是一个使用max
聚合加入子查询的选项:
select a.title, a.artist
from album a join (
select artist, max(rating) maxrating
from almum
group by artist) t on a.artist = t.artist and a.rating = t.maxrating
如果每个艺术家的评分最高,则可以返回多个标题。
也许使用
outer join
更容易:select a.*
from album a
left join album a2
on a.artist = a2.artist and a.rating < a2.rating
where a2.rating is null
SQL Fiddle Demo
关于mysql - 如何获得每位歌手评价最高的专辑?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33511232/