我正试着按照我所问的问题的数量来对用户进行排名。
列'Users.Reputation‘在select列表中无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中。
这是代码https://data.stackexchange.com/stackoverflow/query/1239556/users-with-most-questions#resultSets
select count(OwnerUserId),OwnerUserId,Reputation,DisplayName
from Posts
left join Users on Users.Id = OwnerUserId
where PostTypeId=1
group by OwnerUserId
order by count(OwnerUserId) desc;发布于 2020-05-17 11:14:27
错误似乎很明显:您需要在GROUP BY中包含所有非聚合列。
select count(u.id), p.OwnerUserId, u.Reputation, u.DisplayName
from Posts p left join
Users u
on u.Id = p.OwnerUserId
where p.PostTypeId = 1
group by p.OwnerUserId, u.Reputation, u.DisplayName
order by count(*) desc;我会注意到,这在我看来很尴尬;我不认为LEFT JOIN是必要的。您只需在GROUP BY和SELECT中使用GROUP BY。
https://stackoverflow.com/questions/61850627
复制相似问题