码迷,mamicode.com
首页 > 其他好文 > 详细

快速去重复

时间:2018-01-20 17:50:24      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:gps   var   约束   sele   group   重复   blog   快速   max   

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

快速去重复

标签:gps   var   约束   sele   group   重复   blog   快速   max   

原文地址:https://www.cnblogs.com/linyijia/p/8321266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!