SQL重复

时间:2015-07-27 12:59:15

标签: sql oracle duplicates invoice

上下文, - 有一个大发票数据库。我正在寻找重复项目。目前的情况让我在发票号码中寻找重复。我使用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

这给出的输出是: 供应商ID,供应商名称,发票编号,金额,日期等。(我现在只关注发票编号)

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

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

2 个答案:

答案 0 :(得分:0)

您只需将Count(*)替换为Count(Invoice_Number)即可。可能有用。

答案 1 :(得分:0)

替换:

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) ..
相关问题