从 Hibernate Group By 获取最大计数
To get Max count from Hibernate Group By
如何使用条件和投影在休眠中实现以下代码:
select CUSTOMER_NO,count(*) as max_count
from table
group by CUSTOMER_NO
having count(*) in
(
select
max(count)
from
(
select count(*) as count,CUSTOMER_NO
from table
group by CUSTOMER_NO
) t1
)
查询可以更改为:select CUSTOMER_NO, count(*) as count from temp.t group by CUSTOMER_NO order by count desc limit 1;
同样的标准是:
criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("CUSTOMER_NO")).add(Projections.rowCount(), "count"));
criteria.addOrder(Order.desc("count"));
criteria.setMaxResults(1);
return criteria.list();
如何使用条件和投影在休眠中实现以下代码:
select CUSTOMER_NO,count(*) as max_count
from table
group by CUSTOMER_NO
having count(*) in
(
select
max(count)
from
(
select count(*) as count,CUSTOMER_NO
from table
group by CUSTOMER_NO
) t1
)
查询可以更改为:select CUSTOMER_NO, count(*) as count from temp.t group by CUSTOMER_NO order by count desc limit 1;
同样的标准是:
criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("CUSTOMER_NO")).add(Projections.rowCount(), "count"));
criteria.addOrder(Order.desc("count"));
criteria.setMaxResults(1);
return criteria.list();