MySQL, w/ query / Error代码:1111。使用组函数无效。

[en]MySQL, Confused w/ query / Error Code: 1111. Invalid use of group function.


I have 3 tables.

我有三个表。

  Video (Id, ViewCount, Location)
  Likes (Id, Video, User)
  Location (Id, Name) 

How would I query the four highest ranked videos (sum of Video.ViewCount + count(Likes.User) Group them by Video.Id, and return the top 4 results from a specific location.

如何查询排名最高的四个视频(视频总和)?ViewCount + count(Likes.User)按视频分组。Id,并返回来自特定位置的前四个结果。

I've tried this:

我已经试过这个:

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;

But I get an invalid use of group function. Does anybody have any pointers ??

但是我得到的组函数的使用是无效的。有人有什么建议吗?

1 个解决方案

#1


3  

SELECT  id,
        viewcount +
        (
        SELECT  COUNT(*)
        FROM    likes l
        WHERE   l.video = v.id
        ) AS points
FROM    video v
WHERE   location = 30
ORDER BY
        points DESC, id
LIMIT 4



注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号