I am trying to delete orders for a given customer on a given date and add
the cost of those orders to credit for the customer.

So far, I came up with this:
```
with data as (
    delete from orders
        where customer_id = <customer id>
    and date = '2020-10-05' returning price
), total as (
    select sum(price) from data
)
update paymentdetail
set temp_credit = temp_credit + (select * from total)
where customer_id = <customer id>
```

which works. but is there a better way to update one table using the result
of deleting rows from another table given that I only want the aggregate of
the result?

Reply via email to