2016-10-03 105 views
-2

我從SQL使用獲取所有反向值以下查詢如何刪除反向值在SQL Server

select a.* from TotalsByGLCenter$ as a 
left join TotalsByGLCenter$ as b on a.APSupplierID = b.APSupplierID AND a.Entity=b.Entity and a.ExpenseReportID=b.ExpenseReportID and a.Employee=b.Employee and a.Amount = -b.Amount 
where b.Amount is not null 

我完全有5000行。我有相同的價值消極和積極的我稱之爲倒數值。我從5000行中得到表中所有反向值完全反向值1508列。上面我提到查詢使用提取反向值。我想如果你想刪除您的查詢返回完全相同的記錄刪除反向值

+0

您的要求不明確 – TheGameiswar

+0

您的意思是說負面的價值? – Bharat

+0

你的意思是刪除同一供應商存在另一行的所有行,數量相同,但爲負數?例如。行取消彼此的價值? – Bridge

回答

1

,這裏是你如何做到這一點(你就必須按比例要從刪除表的別名):

delete a 
from TotalsByGLCenter$ as a 
left join TotalsByGLCenter$ as b on a.APSupplierID = b.APSupplierID AND a.Entity=b.Entity and a.ExpenseReportID=b.ExpenseReportID and a.Employee=b.Employee and a.Amount = -b.Amount 
where b.Amount is not null