sql server - Sum sale amount from one table and update the total to another table -
using sql server compact edition (2008 r2)
- tables (
customer
,orders
) - pk (customer :
sid
, orders :customer_sid
)
i want sum orders.sales_amount
, write totals customer.sales_total
based on sid
s.
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)
Comments
Post a Comment