我有一个捐赠表,我正在尝试计算每个月的总金额。几个月没有任何捐款,我希望结果返回 0。
这是我当前的查询:
Donation.calculate(:sum, :amount, :conditions => {
:created_at => (Time.now.prev_year.all_year) },
:order => "EXTRACT(month FROM created_at)",
:group => ["EXTRACT(month FROM created_at)"])
返回:
{7=>220392, 8=>334210, 9=>475188, 10=>323661, 11=>307689, 12=>439889}
任何想法如何抓住空的月份?