Reputation: 5075
Ok so I have a users table and a payments table. Each payment has a date_paid and amount_paid. I would like to group the payments by the sum of the amount paid, but I would also like to keep a field for a last date_paid. Is this possible? Or will I have to store a last_date_paid column within the user table?
Upvotes: 0
Views: 123
Reputation: 12670
SELECT id, SUM(amount_paid), MAX(date_paid)
FROM payments
GROUP BY id
Upvotes: 3