0
我在QueryDSL中使用Spring Data JPA,並試圖在where條件中使用Sum函數,因爲我使用分頁,所以我必須先計數。 所以我有一個像下面的Java代碼: -帶有QueryDSL的Spring Data JPA,帶聚合函數的Count問題
NumberPath<Double> path = entityPath.getNumber("qty", Double.class);
BooleanExpression exp = path.sum().loe(120);
JPQLQuery countQuery = from(stock).where(exp);
long count = countQuery.count();
其創建這樣的查詢: -
select count(stock0_.stock_id) as col_0_0_ from stock stock0_
where sum(stock0_.qty)>=120;
和我收到Error Code: 1111. Invalid use of group function
。
以上查詢不在SQL
以及因爲和功能不能用於計數在哪裏條件。我不知道如何處理這樣的問題,當我必須先計算並獲取真實數據。 有人可以幫我解決這個問題的方法是什麼JPA
。
請不要建議@Query
註釋,因爲我不能使用它。由於動態過濾的要求。
不,我不使用組函數 –
其中sum(stock0_.qty)> = 120是一個組函數。這應該使用having()比較或使用JPASubquery。 – crm86
能否請你詳細解釋一下或提供任何鏈接。如何通過配頁使用 –