class User { hasMany = [ratings: Rating] } class Item { hasMany = [ratings: Rating] } class Rating { belongsTo = [user: User,item: Item] }
我想计算在一个项目上评分的不同用户.
以下内容不起作用:
select count(distinct(r.user)) from Rating as r where r.item=:item group by r.user
如何修改HQL查询以使其正常工作?
select count(distinct r.user) from Rating as r where r.item = :item group by r.user
执行此查询的其他更长时间的方法是使用用户和连接:
select count(distinct u) from User as u inner join u.ratings as r where r.item = :item group by r.user