【发布时间】:2011-12-20 12:29:14
【问题描述】:
我有 3 张桌子。
Video (Id, ViewCount, Location)
Likes (Id, Video, User)
Location (Id, Name)
如何查询排名最高的四个视频(Video.ViewCount + count(Likes.User) 的总和 按 Video.Id 对它们进行分组,并返回来自特定位置的前 4 个结果。
我试过这个:
SELECT Video.Id, sum(Video.ViewCount + count(Likes.User)) as Points From Video
Left Join Likes
ON Likes.Video=Video.Id
WHERE Video.Location=30
GROUP BY Video.Id
ORDER BY Points DESC
LIMIT 4;
但是我得到了对组功能的无效使用。有没有人有任何指针?
【问题讨论】:
-
您不能在其他聚合函数中使用聚合函数。
标签: mysql sql mysql-error-1111