如何使用HQL检索具有最低投票数的最佳文章的排序列表?
我的 grails 应用程序有一个 Vote
域类,其中包含 article_id
和 note
等属性,
我想通过 HQL 查询 Vote
> 域类,以便检索至少有 10 票的 5 篇评分最高的文章。
我尝试过:
SELECT v.article_id, avg(v.note), count(*) FROM vote v where count(*) >= 10 group by v.article_id order by avg(v.note) desc limit 5;
但不幸的是插入 where count(*) >= 10
会引发错误。
我怎样才能以简单的方式做到这一点?
感谢您的帮助。
I have a Vote
domain class from my grails application containing properties like article_id
and note
I want to HQL query the Vote
domain class in order to retrieve the 5 best rated articles having at least 10 votes.
I tried :
SELECT v.article_id, avg(v.note), count(*) FROM vote v where count(*) >= 10 group by v.article_id order by avg(v.note) desc limit 5;
But unfortunately the insertion of where count(*) >= 10
throws an error.
How can I do that in a simple way?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于无法测试它,我不愿意尝试猜测最终查询会是什么样子,但是
HAVING COUNT(*) >= 10
可能值得一看。http://www.sqlcommands.net/sql+having/
Not being able to test it, I'm reluctant to try to guess how the final query would look like, but
HAVING COUNT(*) >= 10
might be something to look at.http://www.sqlcommands.net/sql+having/
尝试一下:
Try that:
以下不起作用吗?
稍后编辑:试试这个
doesn't the following work ?
Later edit: Try this