我在PostGreSQL中遇到困难组。我下面PosgreSQL ActiveRecord :: StatementInvalid:PG :: GroupingError:错误:必须出现在GROUP BY
Invoice.select("customer_id, due_date, sum(balance) AS total_balance, total_mount").group(:customer_id)
代码,我得到了错误
Invoice Load (1.8ms) SELECT customer_id, due_date, sum(balance) AS total_balance, total_amount FROM "records" WHERE "records"."type" IN ('Invoice') GROUP BY "records"."customer_id"
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "records.due_date" must appear in the GROUP BY clause or be used in an aggregate function
enter code here
LINE 1: SELECT customer_id, due_date, sum(balance) AS total_balance,...
UPDATE
感谢@slicedpan的解决方案。我有像下面的代码更新。
Invoice.select("customer_id, MAX(due_date), SUM(balance) AS total_balance").group(:customer_id)
我已经阅读了很多关于这方面的文章,但它仍然显示错误。谢谢
谢谢。我想先尝试一下。 – akbarbin
感谢您的建议。它正在工作。 – akbarbin