0
我正在使用Postgres。这将返回按用户分组的所有付款,这很好地工作。我如何求和这个查询
@users_with_payments = Payment.all(select: 'distinct(users.*)', joins: :user)
我需要将每个用户的总付款金额总和为该金额。当尝试这个,我得到这个错误
@users_with_payments = Payment.all(select: 'distinct(users.*), SUM(payments.amount_cents)', joins: :user)
PG::Error: ERROR: column "users.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT distinct(users.*), SUM(payments.amount_cents) FROM "p...
任何想法,我做错了什么是构建此查询的正确方法?