sql语句删除重复内容,保留一条,id不同,通过后面4个字段内容相同则删除该记录
idnameclasstypect14455266244552663112213341122133执行sql语句后,变为idnameclasstypect24455266...
id name class type ct
1 44 55 2 66
2 44 55 2 66
3 11 22 1 33
4 11 22 1 33
执行sql语句后,变为
id name class type ct
2 44 55 2 66
4 11 22 1 33 展开
1 44 55 2 66
2 44 55 2 66
3 11 22 1 33
4 11 22 1 33
执行sql语句后,变为
id name class type ct
2 44 55 2 66
4 11 22 1 33 展开
3个回答
展开全部
可亏裂仿以这样销纤删除源毕
delete from table1 where id not in(
select id from table1 a where id = (select max(id) from table1 b where a.name = b.name and a.class = b.class and a.type = b.type and a.ct = b.ct))
delete from table1 where id not in(
select id from table1 a where id = (select max(id) from table1 b where a.name = b.name and a.class = b.class and a.type = b.type and a.ct = b.ct))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚经过测试的,版本在MSSQL05以昌蠢上就成。提供质量保证。
delete from t1
where id in (select id from
(select id,row_number() over(partition by name,class,[type],ct order by id desc, name,class,[type],ct)as num from t1)as tmp where num>1)
呵呵,耐盯陪祝你好则核运~
delete from t1
where id in (select id from
(select id,row_number() over(partition by name,class,[type],ct order by id desc, name,class,[type],ct)as num from t1)as tmp where num>1)
呵呵,耐盯陪祝你好则核运~
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
delete from 表名 where id not in(select max(id) from 表名 group by [name],class,[type],ct)
根据后面4个字段分组漏败查梁帆询不是重复的id,
删除重复的橡搜雹ID
根据后面4个字段分组漏败查梁帆询不是重复的id,
删除重复的橡搜雹ID
追问
表中id没有重复的,就是id不同,后面4个字段内容相同的时候,把这些id不同,后面字段内容相同的数据删除后保留一条
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询