SQL 重复

SQL Duplication

上下文,- 有一个很大的发票数据库。我正在寻找重复项。目前的情况让我开始寻找重复的发票号码。我正在使用 count(*) 查找重复项并向我展示重复项,同时忽略其他项。

问题 - Count(*) 不工作,它确实显示了我作为测试数据放入的虚拟重复项,但它仍然显示不是重复项的记录。

这是代码的一部分,您可以了解其中的要点:

sql dbselect s2.apar_id, s2.ext_inv_ref as John3, s2.ext_inv_ref as INVNO, s2.cur_amount, ABS(s2.cur_amount) as ABSAMT, s2.trans_date, s2.period, s2.voucher_no, s2.voucher_type,s3.apar_name, s3.apar_gr_id

sql from asuhistr s2, asuheader s3

sql where ( s2.ext_inv_ref in
sql (select s2.ext_inv_ref
    sql from asuhistr s1
    sql and s1.apar_id = '######'
    sql group by s2.ext_inv_ref
    sql having (count(*)> 1))

遗憾的是它没有删除不重复的发票编号。

如有任何帮助,我们将不胜感激。

完整代码如下:

sql dbselect s2.apar_id, s2.ext_inv_ref as John3, s2.ext_inv_ref as INVNO, s2.cur_amount, ABS(s2.cur_amount) as ABSAMT, s2.trans_date, s2.period, s2.voucher_no, s2.voucher_type,s3.apar_name, s3.apar_gr_id

sql from asuhistr s2, asuheader s3
sql where ( s2.ext_inv_ref in
sql (select s2.ext_inv_ref
    sql from asuhistr s1
    sql and s1.apar_id = '######'
    sql group by s2.ext_inv_ref
    sql having (count(*)> 1))
sql and s3.client = s2.client
sql and s3.apar_id = s2.apar_id
sql and s2.apar_id = '######'
sql order by s2.apar_id
query

给出的输出是: Supplier ID, Supplier Name, Invoice Number, Amount, Date, etc..(我现在只关注发票号)

例如,运行上面的代码给我:

Supplier ID     Supplier Name       Invoice Number
123456            Abcdefg              999999
568224            rtyuiop              445254
782387            asdasda              999999
734756            werqewq              215423
331231            hdfgsaf              515154

我希望它只显示:

Supplier ID     Supplier Name       Invoice Number
123456            Abcdefg              999999
782387            asdasda              999999

您可以将 Count(*) 替换为 Count(Invoice_Number)。可能是这样。

替换:

s2.ext_inv_ref

与:

s1.ext_inv_ref

在您的子查询中:

... (select s1.ext_inv_ref
from asuhistr s1
    and s1.apar_id = '######'
group s1.ext_inv_ref
having (count(*)> 1) ..