sql中有重复数据,只想保留其中一条,其他的全部删除,请问应该怎么写sql 语句呢
5条回答 默认 最新
- chuifengde 2022-09-13 09:55关注
declare @a table(id int,编码 int,金额 int,组织 varchar(20)) insert @a select 1,11,1,'a' union all select 2,11,1,'a' union all select 3,13,3,'a' union all select 4,13,3,'a' union all select 5,14,5,'b' union all select 6,14,5,'b' select * from @a a where not exists(select 1 from @a b where 编码=a.编码 and 金额=a.金额 and id<a.id) --result /* id 编码 金额 组织 1 11 1 a 3 13 3 a 5 14 5 b */
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报