I’m trying to sum each day in the last two weeks.
This code:
Invoice.group('date(filled_at)').sum(:lines_price).to_a
returns:
[["2012-12-15", #<BigDecimal:ac40068,'0.19275E4',18(45)>], ["2012-12-17", #<BigDecimal:a759234,'0.764235E3',18(45)>]]
Which is correct but I need it the return the values in the last two weeks even if the value is 0.0.
So the result should be:
[["2012-12-03", 0.0], ... , ["2012-12-17", #<BigDecimal:a759234,'0.764235E3',18(45)>]]
Thank you.
UPDATE
having("date(filled_at) > ?", Date.today - 14)
solves the last 14 days question. But I still don’t know how to show 0.0 values.
You’re going to have a hard time doing this in SQL because you are trying to force the db to return values that don’t exist. It is much easier to do this in ruby. Here is a succinct way: