从Hibernate Group By获得最大计数

时间:2017-08-17 05:24:45

标签: hibernate projection hibernate-criteria

如何使用条件和投影在hibernate中实现以下代码:

is_featured

1 个答案:

答案 0 :(得分:2)

查询可以更改为: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();