sql server - Sum sale amount from one table and update the total to another table -


using sql server compact edition (2008 r2)

  1. tables (customer , orders)
  2. pk (customer : sid, orders : customer_sid)

i want sum orders.sales_amount , write totals customer.sales_total based on sids.

i must using inner join statement incorrectly error in from statement.

update customer set sales_total = aggr.sales_total customer inner join (     select sid         ,sum(sales_amount) sales_total     customer     inner join orders         on (customer.sid = orders.customer_sid)     group customer.sid     ) aggr     on customer.sid = aggr.sid; 

there simpler way of accomplishing update after:

update customer set sales_total = (select sum(sales_amount)                    orders                    orders.customer_sid = customer.sid) 

demo here


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -