1

在 Oracle 中显示重复行的理想方式是什么?这里的诀窍是我正在寻找所有行,而不仅仅是倍数(重复)。因此,例如在以下数据集上:

RSN fname   lname   emailaddress
1   John    Smith   j.smith@system.com
2   John    Smith   j.smith@system.com
3   John    Smith   j.smith@system.com
4   Kevin   Walker  k.walker@system.com
5   James   Kirk    j.kirk@system.com
6   James   Kirk    j.kirk@system.com
7   Kevin   James   k.james@system.com
8   Mike    Jones   m.jones@system.com

我希望返回以下内容:

1   John    Smith   j.smith@system.com
2   John    Smith   j.smith@system.com
3   John    Smith   j.smith@system.com
5   James   Kirk    j.kirk@system.com
6   James   Kirk    j.kirk@system.com

有什么帮助吗?

4

2 回答 2

1

这是一种方法:

SELECT RSN, fname, lname, emailaddress
  FROM whatever_your_table_is_named t1
 WHERE ( SELECT COUNT(1)
           FROM whatever_your_table_is_named t2
          WHERE t2.fname = t1.fname
            AND t2.lname = t1.lname
            AND t2.emailaddress = t1.emailaddress
            AND ROWNUM < 3
       ) > 1
;

这是另一个:

SELECT t1.RSN, t1.fname, t1.lname, t1.emailaddress
  FROM whatever_your_table_is_named t1
  JOIN ( SELECT fname, lname, emailaddress
           FROM whatever_your_table_is_named
          GROUP
             BY fname, lname, emailaddress
         HAVING COUNT(1) > 1
       ) t2
    ON t1.fname = t2.fname
   AND t1.lname = t2.lname
   AND t1.emailaddress = t2.emailaddress
;

(免责声明:我没有测试过这些。)

于 2013-07-24T18:51:44.173 回答
0

此子查询将从表中获取重复项。

    select *
    from (some table)
    where rsn IN (select rsn
                  from (some table) 
                   where fname IN 
                   (select fname
                    from (select fname, count(fname) as dup 
           from (some table)) where dup > 1)
于 2013-07-24T19:37:48.927 回答