2012-04-20 25 views
0

我在我的hibernate創建條件查詢中對數字字段求和。我需要另一列 - 從輸出resultlist域類seriesType,但現在如果我添加術語property('seriesType')中的突起隨着grouProperty()行我得到一個異常說not a group by clause could not execute query在grails中使用HibernateCriteriaBuilder從createCriteria中提取所有字段

不知道我怎樣才能得到這裏與結果 其他兩個沿着場是我的標準

dataMap = BehaviorProfile.createCriteria().list { 
        globalUser{ 
         eq('id',empid2) 
        } 

        projections{ 
         sum('frequency', 'tfreq') 
         groupProperty('dayofweek') 
        // if I add property('seriesType') here the criteria throws an exception 
        } 

       } 

回答

1

您需要添加groupProperty('seriesType')property('seriesType')。當你通過一些屬性A進行分組並且使用聚合函數 - 在你的情況下求和 - 你不能僅僅輸出一些其他屬性B,因爲在你的B preoperty中也可能有很多值。

例如,在您的dayofweek = 2聚合組中,總數爲150,並且有三種可能的seriesTypes - siereA,serieB和serieC。這就是爲什麼您需要:只按dayofweek分組或按照seriesTypes將group添加到您的查詢。

相關問題