sql - How to sum amounts according their ID-s -


i have database 2 tables in sql server 2008 express.

my problem following: create trigger sum values in first table , copy sum second one.

for example first table (head) has 5 columns :

  id    transaction    acount    date        total_sum     1    text      acount1   2014.04.15   300    2    text      acount2   2014.04.15   500    3    text      acount1   2014.04.15   200 

and second table transaction:

headid amount remarks

1       100        test1 1       200        test2 2       500        test3 3       100        test3 3       100        test4  

so sum values in transaction if have same headid , copy result head table. (total_sum column).maybe first find last id in 'head' table , group headid-s in 'transaction' table , sum values

please me!

you can update table using join

update h set h.total_sum = t.sumtotal head h inner join  ( select headid,sum(amount) sumtotal [transaction] group headid ) t on h.id=t.headid 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -