sql - Find duplicate values in SQL search
问题描述
I'm having a problem finding the right solution for this problem. I want to find duplicate invoices in a list of thousands of invoices and want to make sure were not paying the same invoice twice where the same invoice has been scanned in to our system twice but where the invoice number is not the same but has the same supplier id. I have tried to use COUNT to find all the invoices that have the same supplier id and the same amount but cannot get it to work.
(In the example I want to find the two Johns Bakery invoices)
解决方案
你似乎想要:
select ip.*
from invoice_payment ip
where exists (select 1
from invoice_payment ip2
where ip2.supplier_id = ip.supplier_id and
ip2.name = ip.name and
ip2.amount = ip.amount and
ip2.invoice_number <> ip.invoice_number
)
order by supplier_id, name, amount;
推荐阅读
- c# - Amazon S3 上 ListObjects 的过滤结果
- c# - PDFsharp DrawRoundedRectangle 参数
- sql - 加入时重复记录
- xml - 在 XSLT 的 For 循环中拉取嵌套标签
- android - 从后台返回 Activity 时做某事
- javascript - 对期望为 'number | 的属性使用泛型类型值 字符串 | 不明确的'
- java - 如何正确地为内部类创建对象?
- kubernetes - 如何让 jupyter-hub 访问我的私有 Docker 映像存储库?
- ruby-on-rails - “人”是轨道上的保留词吗?
- c# - 使用 StringComparison 或类似方法替代 string.ToUpper(),完全保留行为