hql查询从每个组中检索前n个 [英] hql query to retrieve top n from each group

查看:87
本文介绍了hql查询从每个组中检索前n个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在HQL中实现以下功能 -

从table1中选择top n其中table1.id IN(某些选择子查询)

我已经找到了setMaxResult(n)方法,但它只能检索整个结果的前n个字段,但是我想实现的是每个小组的前n ...

感谢...

解决方案

这里是您需要的JPQL:

从雇员中选择a
where

)选择来自员工的计数(*)b
其中
a.department = b.department和
a.salary <= b.salary
)<= 10
按工资排序DESC


i want to achieve the following in HQL -

select top n from table1 where table1.id IN (some select sub query)

i have found the setMaxResult(n) method, but it can only retrieve top n of the entire result.. but what i want to achieve is top n of each group...

Thanks...

解决方案

Here is JPQL you need:

select a from Employee a
where
(
    select count(*) from Employee b
    where 
       a.department = b.department and
       a.salary <= b.salary
) <= 10
order by salary DESC

这篇关于hql查询从每个组中检索前n个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆