34,838
社区成员




select identity(int,1,1) as id,*
into #tmp
from record
select * from #tmp t
where not exists(
select 1 from #tmp where sCardID=t.sCardID
and cRemain+t.cRemain=0 and cRemainBefore=cRemainAfter and id<>t.id
)
select identity(int,1,1) as id,*
into #tmp
from record
select * from #tmp t
where not exists(
select 1 from #tmp where sCardID=t.sCardID
and cRemain+t.cRemain=0 and cRemainBefore=cRemainAfter
)
没测试数据,你测下看行不行。delete t from tb t where exists(select 1 from tb where scardid=t.scardid and cRemain<>t.cremain )
delete t from tb t where exists(select 1 from tb where scardid=t.scardid and cRemain<>t.cremain and dttime=t.dtime)