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那么上面就是专辑,我怎么才能得到每个艺术家自己的最高评分专辑呢?
提前谢谢。
发布于 2015-11-04 07:45:26
下面是使用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 发布于 2015-11-04 07:50:22
SELECT*
FROM(SELECT* FROM`Album` ORDER BY `Artist`, `Rating` DESC) x
GROUP BY `Artist`有关更多信息,请参阅this question,它们非常相似。基本上,对它进行排序,以便按艺术家重新排列表格,每个表格的最高评分在顶部,然后对其进行分组,以拉出每个表格的第一条记录。
https://stackoverflow.com/questions/33511232
复制相似问题