Oracle中列的重复组合

时间:2016-12-28 07:14:29

标签: oracle11g

我有一个表格,其中包含如下数据,其中LINENUM和RCPTNUM的组合对于每个PONUM和SITE应该是唯一的。

TextBlock

输出应显示重复组合列表

PONUM LINENUM RCPTNUM SITE
1000     1      1      XXX
1000     1      2      XXX
1000     1      3      XXX
1000     2      1      XXX
1000     2      1      XXX
1001     1      1      XXX
1001     1      1      XXX

2 个答案:

答案 0 :(得分:0)

试试这个:

select PONUM, 
       LINENUM, 
       RCPTNUM ,
       SITE 
from 
( --Preparing dataset
 with tbl( PONUM, LINENUM, RCPTNUM ,SITE) as 
(select 1000,     1 ,     1 ,     'XXX' from dual
 UNION ALL
 select 1000,     1,      2,      'XXX' from dual
 UNION ALL
 select 1000,     1,      3,      'XXX' from dual
 UNION ALL
 select 1000,     2,      1,      'XXX' from dual
 UNION ALL
 SELECT 1000,     2,      1,      'XXX' from dual
 UNION ALL
 Select 1001,     1,      1,      'XXX' from dual
 UNION ALL
 Select 1001,     1,      1,      'XXX' from dual )
 ---Dataset end
 ---Query
select PONUM,
       LINENUM,
       RCPTNUM,SITE ,
       row_number()over(partition by PONUM, LINENUM,RCPTNUM,SITE order by PONUM ) rnk
from tbl
)
where rnk = 2 ;

答案 1 :(得分:0)

select PONUM, LINENUM, RCPTNUM, SITE
from yourTable
group by PONUM, LINENUM, RCPTNUM, SITE
having count(1) > 1