介绍两种删除重复行的方式
1.使用临时表,分组找出重复部分的id进行删除
删除table:goods_info 中存在重复goods_id的记录
select identity(int,1,1) as autoId,* into #temptable from goods_info
select min(autoId) as autoid into #temptable1 from #temptable group by goods_id --分组找出autoId
delete from #temptable where autoId in (select autoId from #temptable1)
2.使用分析函数删除
With t as
(
select *, row_number() over (partition by ... order by ...) as RowNum from table_a
)
Delete from t where rownum > 1;