有没有办法按 SOQL 中日期时间字段的日期部分进行分组

问题描述 投票:0回答:1

返回基于日期的结果计数;

SELECT day_only(createdDate) createdonDate, 
    count(createdDate) numCreated 
FROM account 
GROUP BY day_only(createdDate) 
ORDER BY day_only(createdDate) desc

但我希望结果计数基于月份。

有没有办法在soql中实现这一点?

salesforce apex-code soql
1个回答
2
投票

使用 CALENDAR_MONTH 函数:

select CALENDAR_MONTH (createdDate) createdonDate, count(ID) numCreated from account group by CALENDAR_MONTH (createdDate) order by CALENDAR_MONTH (createdDate) desc
© www.soinside.com 2019 - 2024. All rights reserved.