日期:2014-05-17 浏览次数:20583 次
szy_temp里面有重复的数据
insert into szy_max
select gdsid,kqbh,gys,max(lastmodified)
from szy_temp
group by gdsid,kqbh,gys
查询1:
delete szy_temp
from szy_temp a,szy_max b
where a.gdsid = b.gdsid and a.kqbh = b.kqbh and a.gys = b.gys and a.lastmodified < b.lastmodified
select * from szy_temp
查询2:
select *
from szy_temp a,szy_max b
where a.gdsid = b.gdsid and a.kqbh = b.kqbh and a.gys = b.gys and a.lastmodified = b.lastmodified
--szy_temp里面有重复的数据
declare @szy_temp table(gdsid int,kqbh int,gys int,lastmodified datetime)
declare @szy_max table(gdsid int,kqbh int,gys int,lastmodified datetime)
insert into @szy_temp
values(1,1,1,'2013-01-01 00:00:01'),
(1,1,1,'2013-01-01 00:00:05')
insert into @szy_max
select gdsid,kqbh,gys,max(lastmodified)
from @szy_temp
group by gdsid,kqbh,gys
--查询1:
delete @szy_temp
from @szy_temp a,@szy_max b
where a.gdsid = b.gdsid and a.kqbh = b.kqbh and a.gys = b.gys and a.lastmodified < b.lastmodified
select * from @szy_temp
--查询2:
select a.*
from @szy_temp a,@szy_max b
where a.gdsid = b.gdsid and a.kqbh = b.kqbh and a.gys = b.gys and a.lastmodified = b.lastmodified
--楼主还是找一条异常的数据,分析之