ZKX's LAB

sql server 怎么删除表里重复数据 sql server 去除重复数据

2021-04-25知识6

如何使用sql语句在sqlserver中删除重复数据? 我想在sqlserver中删除两列属性中同时重复的数据,不知道sql语句如何实现

sql server 中删除重复数据 我首先分析一下1、你这张考勤表里面可能是多名员工的考勤记录,但是每天都有可能会有肯多刷卡记录;2、考勤表里面有一个主键ID(有可能是序号,每刷一次就递增)、人名Name、日期Date、时间Time等字段因为ID是每刷一次就递增的,所以不用取这个字段,我建议首先把你要保留的记录拿出来,例如保留每个人每天最早时间的记录:select Name,Date,min(Time)from tablegroup by Name,Dateinsert into temp temptab;其次再删除指定日期多余字段delete from tablewhere ID not inselect ID from tablewhere Name=(select Name from temptabwhere Name=table.Nameand Date='制定日期'and Time=table.Time)and Date='指定日期'and time=(select Time from temptabwhere Name=table.Nameand Date='制定日期'and Time=table.Time)如果你不需要制定日期就保留一条记录,那么从第一步开始就不用选择日期字段了

sql server 重复数据删除 1 修改表biao结构,给添加一个列biao_id,自动增长填充,做为biao的主键2 执行删除语句delete*from biao where id in(select b2.idfrom biao b1,biao b2where b1.chinese=b2.chinese and b1.japanese=b2.japanese and b1.english=b2.englishand b1.t1=b2.t1 and b1.t2=b2.t2 and b1.t3=b2.t3and b1.id)3 去掉主键id,即得到原来表结构及相关数据。注的内容没看明白,不知道到底是哪个表数据重复,不便说话。

随机阅读

qrcode
访问手机版