I have two tables:
- Users with ID and Amount_due columns
- Bills with ID, billed_cents, User_Id
I need to sum all the billed_cents in the bills table by ID and update by ID the user's amount_due.
Here is what I am trying so far with no luck
UPDATE users
SET amount_due = (SELECT SUM(billed_cents) FROM bills INNER JOIN users ON bills.user_id = users.id WHERE someConditions)
FROM bills
WHERE users.id = bills.user_id