[英]Find duplicates using SQL based on 3 values including Amount (Integer)
我正在使用一個允許我輸入 SQL 的應用程序,我在其中輸入 select 語句的 Where 子句。 下面的代碼有效。 它返回發票編號和供應商名稱相同的所有記錄。 但我不確定如何還包括 AMOUNT 字段(整數)。 每當我嘗試時,它都會中斷。
convert(nvarchar, Invoice Number+Vendor Name) in
(
select convert(nvarchar, Invoice Number+Vendor Name)
from TABLENAME
where Invoice Number is not NULL and
group by convert(nvarchar, Invoice Number+Vendor Name)
having count(*) >1)
使用exists
。 這是一個有代表性的查詢:
select t1.*
from t1
where exists (select 1
from tablename t2
where t2.number = t1.number and
t2.vendorname = t.vendorname and
t2.amount = t.amount
group by t2.number, t2.vendorname, t2.amount
having count(*) > 1
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.