[英]Count no of rows with group by clause in criteria
有沒有一種方法可以為以下sql編寫休眠條件:
select count(*) from tableA group by columnA, columnB, columnC;
基本上,我想從默認添加的select子句中排除group屬性。
例:
session.createCriteria(TableA.class)
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("columnA"))
.add(Projections.groupProperty("columnB"))
.add(Projections.groupProperty("columnC"))
.add(Projections.rowCount()));
將導致
select columnA, columnB, columnC, count(*) from tableA group by columnA, columnB, columnC;
謝謝。
請參考以下代碼::
Integer totalResult = ((Number)criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();
您也可以嘗試以下方法:::
int count = ((Long)getSession().createQuery("select count(*) from table_a group by column_a").uniqueResult()).intValue();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.