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

[英]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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2011/11/02/d487f6c677d6bce9f5cfe5c823c623de.html



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