Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help simple sales data

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-02-10 : 23:09:36
my expect result is below , pls give one query for below :=

sales header
trx_no = S0001
trx_no = S0002
anyone can help give a simple query ?

Sales Detail
trx_no = s0001
item_1 $100
item_2 $200
item_3 $300
trx_no = s0002
item 4 $1000
item 5 $1000

I want the result is below and no duplicate trx no must :---
trx_no = s0001 $600
trx_no = s0002 $2000

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2015-02-11 : 05:07:30
select
h.trx_no, dt.itemsum
from header as h
left join (select trx_no, sum(item) as itemsum from deatail as d group by trx_no) as dt
on h.trx_no = dt.trx_no


Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -