日期:2014-05-17 浏览次数:20958 次
select a.*
from tb a
inner join
(
select userid,cardno, convert(varchar(16),collectdetails,120) as collectdetails,COUNT(1) as num
from tb
group by userid,cardno, convert(varchar(16),collectdetails,120)
having COUNT(1)>1
)b on a.userid=b.userid and a.cardno=b.cardno and convert(varchar(16),a.collectdetails,120)=b.collectdetails
if object_id('test',N'U')>0
drop table test
create table test(hospitalid int,userid varchar(5),cardno varchar(10),collectdetails datetime)
insert into test(hospitalid, userid, cardno, collectdetails)
select 1,'001','0E256742','2013-9-22 10:14:15' union all
select 1,'001','0E256742','2013-9-22 10:14:25' union all
select 1,'002','0E256744','2013-9-22 13:14:15' union all
select 1,'002','0E256744','2013-9-22 13:14:25' union all
select 1,'001','0E256742','2013-9-22 13:14:35' union all
select 1,'003','0E256743','2013-9-22 13:15:15' union all
select 1,'003','0E256743','2013-9-22 13:15:45' union all
select 1,'003','0E256743','2013-9-22 13:16:55' union all
select&n