如何通过activationDate获取计数?
我试过这个查询
def mapQuery6= new HashMap()
def query6 = "SELECT count(al.id) as totalCount,al.activationDate from Card al where and TO_DAYS(al.activationDate) > TO_DAYS(:from) and TO_DAYS(al.activationDate) <= TO_DAYS(:to) GROUP BY al.activationDate "
mapQuery6.from = params.from
def to = new Date().parse('dd/MM/yyyy HH:mm:ss', params.to+ " 05:00:00")
to.setDate(to.getDate() + 1)
mapQuery6.to = to
println "query 6 = "+query6
def activecard = Card.executeQuery(query6,mapQuery6)[0]
println "activecard = "+activecard
我想要这样的结果
如果iam使用Group by al.activationDate
打印时的结果是
activecard = [1, 2014-06-17 20:27:11.0]
如果没有group by al.activationDate
,结果是
activecard = [6, 2014-06-27 20:27:11.0]
所以我想每个月都有一个计数号码.. 示例2014-07-xx有3个计数,2014-06-xx 2和2014-05-xx只有1个
答案 0 :(得分:0)
尝试按月分组
GROUP BY MONTH(al.activationDate)