-3

I have two tables like in picture below:

tables example

I change price of one product. Then I need to update total_price in table two for all customers. How to update total_price in table two in one statement for all the customers?

mikery
  • 13
  • 4

1 Answers1

0

You could use update with join

update table_two t2
inner join (
    select id_customer, sum(price) tot
    group by id_customer
) t1 t1.id_customer = t2.id_customer 
set t2.total_price  = t1.tot
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107