Finding duplicate values

后端 未结 2 1778
半阙折子戏
半阙折子戏 2021-01-24 02:43

I have a table called Transfers, and I would like to find all the records that have duplicate values on three columns Doc ID,Amount and Date. Basically what I need is to find w

相关标签:
2条回答
  • 2021-01-24 03:10

    Use This:

    select transfers.doc_id,transfers.date,transfers.amount,count(*) counts
    from transfers
    group by doc_id,date,amount
    having counts>1;
    

    Output will be with Count of duplicate Records:

    doc_id  date        amount  counts
    1234    12/07/2019  3,000   2
    2345    12/07/2019  15,000  2
    4321    12/07/2019  5,600   2
    
    0 讨论(0)
  • 2021-01-24 03:16

    Consider using group by for three columnsgroup by doc_id,Amount,Date

    select t.doc_id,t.date,t.amount
      from transfers t
     where t.date between $P{StartDate} and $P{EndDate}
     group by doc_id,Amount,Date
    having count(doc_id) >1;
    
    0 讨论(0)
提交回复
热议问题