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.
Author |
Topic |
usafelix
Posting Yak Master
165 Posts |
Posted - 2015-02-12 : 09:39:24
|
Dear Sir, I want sum the redemption amount by each trx_no. Because I am join two table . the sales detail have many duplicate trx_no with carry different amount.Thus ,I want to exclude duplicate data (based on just one column -- an trx_no field). Basically, I want to only have one result per trx_no. The entire row won't be unique, however, because one or more fields will be different.so a DISTINCT won't work because the entire row is not a duplicate.--------------------------------------------------------select distinct s.trx_no,s.trx_acc_amt,sum(d.trx_sub_disamt)as Redemption from trx_hdr sinner join trx_dat d on d.trx_no = s.trx_no inner join user_dat u on u.id = s.idgroup by s.trx_no,s.trx_acc_amt-----------------------------------------------------------trx_no |trx_acc_amt | redemption amtMKLTD1412001239 |2270 | 1500MKLTD1412001239 |2270 | 150CB3SW1501001166 | 0 | -750CB3SW1501001166 | 0 | 750T5LSW1408000039 |1200 | 1200T5LSW1408000039 |1200 | 400T5LSW1408000039 |1200 | 500I want to get the result in below. -------------------------------------------------trx_no |trx_acc_amt | redemptionMKLTD1412001239 |2270 | $1650CB3SW15010T5LSW | 0 | 0T5LSW1408000039 |1200 | $2100-------------------------------------------------- |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-02-12 : 11:51:47
|
Please continue the discussion in your other topics rather than starting a new one for the same problem.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|