我使用的方法是:
:
def self.lines_price_report(n)
Income.group('date(filled_at)').having("date(filled_at) > ?", Date.today - n).sum(:lines_price)
end
我在Heroku中遇到了这个错误:
PG::Error: ERROR: column "incomes.filled_at" must appear in the GROUP BY clause
or be used in an aggregate function
How can I fix this? Thank you.
Executed query:
SELECT SUM("incomes"."lines_price") AS sum_lines_price, date(filled_at)
AS date_filled_at FROM "incomes"
HAVING (date(filled_at) > '2012-12-04')
GROUP BY date(filled_at) ORDER BY filled_at ASC
期望的结果
[["2012-12-04", SUM_FOR_DATE], ["2012-12-05", SUM_FOR_DATE], ...]
reorder
而不是unsocped
。我已经修改了答案。 - sufleR