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...
이 쿼리를 구성 할 수있는 올바른 방법 일 것입니다 무슨 내가 잘못하고 어떤 생각을 얻을?