我有 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;
但是我对组功能的使用无效。有没有人有任何指针?