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

Поиск
Список
Период
Сортировка
От Pankaj Jangid
Тема Re: How to update a table with the result of deleting rows in another table
Дата
Msg-id m28scjkg2w.fsf@codeisgreat.org
обсуждение исходный текст
Ответ на How to update a table with the result of deleting rows in another table  (Hemil Ruparel <hemilruparel2002@gmail.com>)
Список pgsql-general
On Tue, Oct 06 2020, Hemil Ruparel wrote:


> 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>

Not sure about better way but will this also not work? I just removed
the second clause.

#+BEGIN_SRC sql
with data as (
    delete from orders
        where customer_id = <customer id>
    and date = '2020-10-05' returning price
)
update paymentdetail
set temp_credit = temp_credit + (select sum(price) from data)
where customer_id = <customer id>
#+END_SRC




В списке pgsql-general по дате отправления:

Предыдущее
От: Hemil Ruparel
Дата:
Сообщение: How to update a table with the result of deleting rows in another table
Следующее
От: Mark
Дата:
Сообщение: Re: How to execute the sql file in PSQL