認爲是我的模型:如何通過hibernate獲得羣組查詢結果的總數?
public class UserActions {
private int id;
private String username;
private String actionType;
// setter and getters here
}
現在我想執行這個下面的查詢,並顯示在表中的結果與分頁:
select t.username, t.actionType
from UserActions t
group by t.username, t.actionType
這是查詢結果:
現在如果我執行此查詢以獲得總記錄數:
select count(*)
from UserActions t
group by t.username, t.actionType
這shoulde是結果:
實際上,如果我想獲得總記錄數,是應該這樣執行查詢:
select count(*)
from (
select count(*)
from UserActions t
group by t.username, t.actionType)
,但你也知道上面的查詢無法執行,因爲hibernate不支持from
子句中的子查詢。
UPDATE
我很困惑 我發現,通過節計算與組總數的查詢:
select sum(count(*) - count(*) + 1)
from UserActions a
group by a.username, a.actionType
,它工作正常在Oracle但在Postgres沒有工作, MySQL的。
休眠支持statament? –
你是否指'帶'條款?不支持。 –
如果你想獲得總數,爲什麼不運行簡單的'SELECT count(*)FROM UserActions t'?我不明白你的問題。 – krokodilko