1
SupplierId NetAmt
1 400
2 400
3 300
2 200
SupplierId RecdAmt
2 200
2 200
2 200
Expectect結果:如何總結兩個表格的結果?
1 400
3 300
第一個表是對內表和二表是支付表,當我做支付給供應商誰的完全完成支付應不再顯示
SupplierId NetAmt
1 400
2 400
3 300
2 200
SupplierId RecdAmt
2 200
2 200
2 200
Expectect結果:如何總結兩個表格的結果?
1 400
3 300
第一個表是對內表和二表是支付表,當我做支付給供應商誰的完全完成支付應不再顯示
你可以像這樣
select SupplierId , NetAmt from table1
where SupplierId not in (select SupplierId from table2)
或
喲ü也可以嘗試這個
SELECT SupplierId , NetAmt
FROM Table1 t1
LEFT JOIN Table2 t2 ON t1.SupplierId = t2.SupplierId
WHERE t2.SupplierId IS NULL
看來你需要取得平衡每個供應商
SELECT ISNULL(NetTable.SupID, RecTable.SupID) AS SupID, (ISNULL(NetTable.TotalNet,0) - ISNULL(RecTable.TotalRec,0)) AS BalAmt
FROM (SELECT SupID, SUM(NetAmt) AS TotalNet FROM Table_1 GROUP BY SupID) AS NetTable
LEFT OUTER JOIN
(SELECT SupID, SUM(RecAmt) AS TotalRec FROM Table_2 GROUP BY SupID) AS RecTable
ON NetTable.SupID = RecTable.SupID
WHERE NetTable.TotalNet <> RecTable.TotalRec
極品GROUP BY供應商的每個表單獨& JOIN摘要。
獲取輸出的邏輯是什麼..請詳細說明問題 –
不要忘記將它標記爲已接受,如果它適合您... –