Rails / Postgres: “must appear in the GROUP BY clause or be used in an aggregate function”

前端 未结 3 449
刺人心
刺人心 2021-01-19 05:41

I\'m using this method:

  def self.lines_price_report(n)
    Income.group(\'date(filled_at)\').having(\"date(filled_at) > ?\", Date.today - n).sum(:lines_         


        
3条回答
  •  星月不相逢
    2021-01-19 06:22

    When you want to use Group By on PostgreSQL, The select option should be required on the group by.

    Income.select('filled_at').group('date(filled_at)').having("date(filled_at) > ?", Date.today - n).sum(:lines_price)
    

提交回复
热议问题