打破日期day
,month
和year
則忽略該項timestamp
。
這應該給你你需要的東西。
def query =
"""
select new map(day(u.creationDate) as day,
month(u.creationDate) as month,
year(u.creationDate) as year,
count(u) as count)
from UserProfile as u
group by day(u.creationDate),
month(u.creationDate),
year(u.creationDate)
"""
//If you do not worry about dates any more then this should be enough
def results = UserProfile.executeQuery(query)
//Or create date string which can be parsed later
def refinedresults =
results.collect { [ "$it.year-$it.month-$it.day" : it.count ] }
//Or parse it right here
def refinedresults =
results.collect {
[ Date.parse('yyyy-MM-dd', "$it.year-$it.month-$it.day") : it.count ]
}
依賴方言是我不考慮此選項的原因。你是對的。 :) – dmahapatro