在Oracle中选择重复的列组合

时间:2014-05-12 06:36:56

标签: sql oracle

我知道我的数据库中的某些记录在某些列中的重复日期相同。我需要找出这些重复项以及它们被复制的次数,所以我写了这个查询:

select tran_date,foracid, TRAN_PARTICULAR,part_tran_type, tran_amt, count(*) as COUNTS 
from tbaadm.htd,tbaadm.gam 
where gam.acid=htd.acid and tran_particular like '%FEE%' 
AND tran_date between '03-Mar-2014' and '11-Mar-2014'
and htd.acid in(select gam.acid from tbaadm.gam where gam.acct_ownership<>'O')
GROUP BY  tran_date, foracid, TRAN_PARTICULAR, tran_particular, 
part_tran_type, tran_amt
HAVING COUNT(*) > 1
order by 2 desc;

我的计数列不正确,因为我可以在某些时候看到它指出行是2而我有一行。有时行数为10,而同一组合只有一行。

如何获得重复的五列和列组合的行数?

1 个答案:

答案 0 :(得分:2)

试试这个:

SELECT tran_date, foracid, TRAN_PARTICULAR, part_tran_type, tran_amt, count(*) as COUNTS 
FROM tbaadm.htd, tbaadm.gam 
WHERE gam.acid=htd.acid and tran_particular like '%FEE%' 
  AND tran_date between '03-Mar-2014' and '11-Mar-2014'
  AND htd.acid IN (SELECT gam.acid FROM tbaadm.gam WHERE gam.acct_ownership <> 'O')
GROUP BY  tran_date, foracid, TRAN_PARTICULAR, part_tran_type, tran_amt
HAVING COUNT(*) > 1
ORDER BY 2 DESC;
相关问题