Finding Duplicate Entries in a table

我们两清 提交于 2019-12-13 18:19:09

问题


I have a table with the following fields in Oracle 10g.

TABLE_1

account_no | tracking_id | trans_amount

Each account_no can have multiple tracking Id's and transaction amounts.

How do i query out the duplicate entries of account_no where tracking lies between 1 and 1000, and the corresponding trans_amount ?

Many thanks in advance for your help,

novice.


回答1:


Try the following query:

SELECT account_no, tracking_id, trans_amount
FROM TABLE_1
WHERE
account_no IN
    (
    SELECT account_no FROM TABLE_1
    WHERE tracking_id >= 1 AND tracking_id <= 1000
    GROUP BY account_do
    HAVING COUNT(*) > 1
    )

Explanation of the subquery: it finds all the account_no's for which there are more than 1 such that its tracking_id is between 1 and 1000.

I hope that's what you meant.



来源:https://stackoverflow.com/questions/1275930/finding-duplicate-entries-in-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!