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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2000-12-01 : 15:20:58
|
Hendrik writes "There is 2 table
table Order has following structure - szStockCode - sOrderCommand - mnPrice - iOrderNo - nVolume
table Trade has following structure - szStockCode - sTradeCommand - mnPrice - iBuyerOrderNo - iVolume
How to return result set with following condition : - Select from table Order which iOrderNo with sOrderCommand = 0 so, iOrderNo which sOrderCommand = 2, should be ignored (sOrderCommand might be 0-3) - Subtract nVolume from above result with table Trade which sTradeCommand = 0 based on iOrderNo = iBuyerOrderNo - at last, sum nVolume group by mnPrice
eg:
Table Order ----------- szStockCode sOrderCommand mnPrice iOrderNo nVolume ABCD 0 500 000001 1000 ABCD 0 525 000002 2000 ABCD 0 550 000003 500 ABCD 0 550 000004 2000 ABCD 2 500 000001 1000
Table Trade ----------- szStockCode sTradeCommand mnPrice iBuyerOrderNo iVolume ABCD 0 530 000003 500 ABCD 0 530 000004 1000 from above table should return following result set for szStockCode = ABCD
mnPrice nVolume 550 1000 525 2000 How to perform this only in 1 Query ?" |
|
|
|
|
|