2012-11-08 23 views
0

我有一個需要我必須返回一天/一週或一年的計數。Howto GroupBy使用GORM的日/周/年?

例子:假設 我有被放置在某個日期

class Order { 
    Date orderDate 
} 

我怎麼會得到每天的訂單量概述/每週/年等的訂單?

+0

您可以嘗試HQL和日期功能,如這裏所建議的 - http://stackoverflow.com/questions/10222370/can-we-group-by-day-of-the-week-using-hibernate/11461009#11461009 –

回答

0

這是未經測試,但你需要的是這樣的:

class Order { 
    Date orderDate 
    BigDecimal amount 
    static namedQueries = { 
     summaryProojectionByDate = { 
      projections { 
       count("id", "orderCount") 
       sum("amount", "amountSum") 
       groupProperty("orderDate", "orderDate") 
      } 
     } 
    } 
} 

這組的具體日期。我認爲這很難在HQL中按幾周進行分組。

0

我只是偶然發現了this blog,它建議使用新的sqlprojection for Grails 2.0,並且還有用於Grails 1.x的替代解決方案。

相關問題