我试图选择专辑编号最高的乐队,因为它显示错误


  “字段列表”中的未知列“ N_Albums”


我应该怎么做才能看到乐队的名称和专辑号码?

select Name, max(N_Abums) as `Albums`
from (select a.Name, count(b.CodDisc) as `Nr`
    from `S8.Band` a join `S8.Album` b
    where a.CodBand = b.CodBand
    group by a.CodBand) as Test

最佳答案

N_Albums更改为Nr

您为计数加上Nr别名,因此必须采用max()。

select Name, max(Nr) as Albums
from (
    select a.Name, count(b.CodDisc) as Nr
    from S8.Band a
    join S8.Album b on a.CodBand = b.CodBand
    group by a.CodBand
) as Test


我还改进了您的联接语法,并删除了所有不必要的反引号。

关于mysql - 如何从计数中选择最大?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40513859/

10-16 06:41