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-10 : 05:52:54
|
who can help me write a query can combine two statement of result ? I am tried to combine it but happened too many repeat trx_no. ----------------------------------------------------------------select distinct detail.trx_no, sum(detail.redemption_amt) from detail group by trx_noselect distinct header.trx_no , header.sales_total_amt from headergroup by trx_no----------------------------------------------------------------I expect output is below :-trx_no , sales_total_amt, detail.redemption_amt sales_1 $50 $30 |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2015-02-10 : 08:42:49
|
What did you try?Assuming there is only one row for each trx_no in the header table,SELECT h.trx_no, h.sales_total_amt, SUM(d.redemption_amt) AS redemption_amtFROM header h INNER JOIN detail d ON d.trx_no = h.trx_noGROUP BY h.trx_no, h.sales_total_amt; |
|
|
usafelix
Posting Yak Master
165 Posts |
Posted - 2015-02-10 : 09:54:53
|
my expect result is below , pls give one query for below :=sales headertrx_number = S0001 trx_number = S0002 Sales Detailtrx_number = s0001 item_1 $100 item_2 $200 item_3 $300trx_number = s0002 item 4 $1000 item 5 $1000I want the result is below :---Sales number sales amounttrx_no = s0001 $600trx_no = s0002 $2000 |
|
|
|
|
|