日期:2014-05-18 浏览次数:20735 次
select * from test t where (select count(1) from test where a=t.a and b=t.b and c=t.c)>1
------解决方案--------------------
if OBJECT_ID('tb','U') is not null drop table tb
go
create table tb
(
    id int,
    col1 varchar(5),
    col2 varchar(5),
    col3 varchar(5)
)
go
insert into tb
select '1','A','B','C' union all
select '2','A','B','C' union all 
select '3','D','E','F' union all 
select '4','D','E','F' union all 
select '5','G','H','I' union all 
select '6','J','K','L'
go
with cte as 
(
    select 
        ID,
        col1,
        col2,
        col3,
        COUNT(1) over(partition by col1,col2,col3) as v_count
    from tb A
) 
select 
     id,
     col1,
     col2,
     col3
from cte
where v_count>1
--ID Col1 col2 Col3
--1    A    B    C
--2    A    B    C
--3    D    E    F
--4    D    E    F