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...
私が間違っていることと、このクエリを作成する正しい方法は何ですか?