我写了以下查询
示例查询
USE SampleDB
SELECT Sec.SecurityID, Port.PortfolioCode, Sec.SymbolNameSpace, Sec.Symbol,
PT.TradeAmount, PT.tradedate, PT.settledate, PT.PostDate, PT.TransactionCode,
PT.SecurityID1
FROM AdvApp.vPortfolioTransaction PT
LEFT OUTER JOIN
AdvApp.vPortfolio PORT
ON Port.PortfolioID = PT.PortfolioID
LEFT OUTER JOIN
AdvApp.vSecurity Sec
ON Sec.SecurityID = PT.SecurityID1
WHERE Sec.SecurityID = 4678 or Sec.SecurityID = 6
ORDER BY PT.TradeAmount
期望的结果集
SecurityID PortfolioCode SymbolNameSpace Symbol TradeAmount tradedate settledate PostDate TransactionCode SecurityID1
4678 pendingtest caus pending 368,456.00 5/21/2013 NULL 5/21/2013 lo 4678
6 pendingtest caus cash 368,456.15 5/22/2013 NULL 5/23/2013 lo 6
4678 pendingtest caus pending 7,800.00 4/17/2013 NULL 5/21/2013 lo 4678
6 pendingtest caus cash 7,801.00 4/23/2013 NULL 5/23/2013 lo 6
样本实际结果集
SecurityID PortfolioCode SymbolNameSpace Symbol TradeAmount tradedate settledate PostDate TransactionCode SecurityID1
6 pendingtest caus cash 240,453.70 7/16/2010 NULL 7/19/2010 lo 6
6 pendingtest caus cash 249,562.32 1/19/2012 1/19/2012 1/20/2012 dp 6
6 pendingtest caus cash 368,456.15 5/22/2013 NULL 5/23/2013 lo 6
6 pendingtest caus cash 250,000.00 12/1/2003 NULL 12/1/2003 lo 6
6 pendingtest caus cash 250,321.13 11/15/2010 11/15/2010 11/16/2010 dp 6
6 pendingtest caus cash 365,445.58 1/31/1999 NULL 3/26/1999 dp 6
4678 pendingtest caus pending 368,456.00 5/21/2013 NULL 5/21/2013 lo 4678
4678 pendingtest caus pending 7,800.00 4/17/2013 NULL 5/21/2013 lo 4678
6 pendingtest caus cash 7,801.00 4/23/2013 NULL 5/23/2013 lo 6
逻辑是我只想查看行对在 +/- 5 内匹配交易金额的表行。我也只想查看 SecurityID1 值是 4678 和 6 组合的行。这对总是有一行是 SecurityID1 4678,另一行是 SecurityID1 6。
我广泛搜索了如何配对交易,但我找不到任何示例说明如何在 +/- 5 的容差范围内允许类似值