use tb
go

set nocount on

create table #Tmp --创建临时表#Tmp
(
FCarNumber VARCHAR(50) ,
maxid int ,
num int
);

insert into #Tmp(FCarNumber,num,maxid)
select FCarNumber,COUNT(0) as num,Max(PID) as maxid from T_GPSCar with (nolock) group by FCarNumber having count(0)>1

delete T_GPSCar from
#Tmp p where p.FCarNumber=T_GPSCar.FCarNumber and T_GPSCar.PID<>p.maxid

Select COUNT(0) as num from #Tmp --查询临时表的数据
truncate table #Tmp --清空临时表的所有数据和约束
drop table #Tmp
set nocount off

相关文章:

  • 2022-12-23
  • 2021-07-31
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
  • 2021-09-15
  • 2021-10-16
  • 2021-08-31
  • 2022-02-09
相关资源
相似解决方案