sql - How to get sum of multiple records in a column -
i have query this:
select tc.f_exhibition_name, t.f_exhibitor_name, tc.f_creditnoteno, tc.f_description, tc.f_price, tc.f_qty, tc.f_cnqty, tc.f_totalamt t_creditnote tc left join t_exhibitor t on t.f_exhibitor_name = tc.f_exhibitor_name tc.f_creditnoteno='cninv100002'
the output looks this
---------------------------------------------------------------------------------------------------------------------------------------------------- f_exhibition_name f_exhibitor_name f_creditnoteno f_description f_price f_qty f_cnqty f_totalamt ---------------------------------------------------------------------------------------------------------------------------------------------------- workspace 2015 aep - associacao empresarial de portugal cninv100002 item1 12 5 8 96 workspace 2015 aep - associacao empresarial de portugal cninv100002 item2 25 12 10 250
i want add 1 more column [sum]
@ last sum of f_total
amount. in case, want show sum(250+96)
= 346
.
how can this?
use sum over()
:
select tc.f_exhibition_name, t.f_exhibitor_name, tc.f_creditnoteno, tc.f_description, tc.f_price,tc.f_qty, tc.f_cnqty, tc.f_totalamt, sum(tc.f_totalamt) on () sumoftotalamt t_creditnote tc left join t_exhibitor t on t.f_exhibitor_name=tc.f_exhibitor_name tc.f_creditnoteno='cninv100002'
the windowed version of sum
return both rows sum of f_totalamt
.
Comments
Post a Comment