Re: How to update a table with the result of deleting rows in another table

2020-10-06 Thread Michael Lewis
> > Adding the customer id to your returning clause and using update..from > could help: > > with data as ( > delete from orders > where customer_id = > returning customer_id, price > ), total as ( > select customer_id, sum(price) as total_price > from data

Re: How to update a table with the result of deleting rows in another table

2020-10-06 Thread Alban Hertroys
> On 6 Oct 2020, at 7:37, Hemil Ruparel wrote: > > 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 =

Re: How to update a table with the result of deleting rows in another table

2020-10-05 Thread Pankaj Jangid
On Tue, Oct 06 2020, Hemil Ruparel wrote: > with data as ( > delete from orders > where 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) > w

How to update a table with the result of deleting rows in another table

2020-10-05 Thread Hemil Ruparel
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 = and date = '2020-10-05' returning price ), total as ( select su