2016-05-31 25 views
-1

如何與普通的列在SQL表的幫助下找回罕見的列(基於共同的列訂單ID & orderamt需要得到作爲比較獲取與公共列的幫助少見表中的列

例 生數據

SellerID CustID OrderID OrderAmt 
1251  197  1675 2515 
1259  201  1971 5135 
1271  199  1675 2515 
1299  197  1971 5135 
1289  211  1972 5135 

結果

OrderID OrderAmt SellerID CustID SellerID1 CustID1 
1675 2515  1251  197  1271  199 
1971 5135  1259  201  1299  197 
+0

不客氣...... – jarlh

+0

你似乎基於'OrderID'&'OrderAmt'和彙總'CustID'和'SellerId'被希望集團的原始數據。請進一步解釋你想達到的目標。 – Stavr00

+0

你正在使用哪些DBMS? –

回答

0

自加入表由uncom共同列和過濾器週一的:

Select 
    a.OrderID, a.OrderAmt, 
    a.SellerID, a.CustID, 
    b.SellerID As SellerID1, b.CustID As CustID1 
From 
    [SourceTable] a 
Inner Join 
    [SourceTable] b 
On 
    a.OrderID = b.OrderID AND a.OrderAmt = b.OrderAmt 
Where 
    a.SellerID <> b.SellerID OR a.CustID <> b.CustID