sql server删除重复的数据保留一条

DELETE FROM [TCX_1710_SHZJ].[dbo].[PR_BindingTray]
WHERE 1=1
AND SNum in (SELECT * FROM ( (SELECT SNum FROM [TCX_1710_SHZJ].[dbo].[PR_BindingTray] GROUP BY SNum HAVING COUNT( SNum )>1) ) a)
AND id not in (SELECT * FROM ( (SELECT MIN(id) ids FROM [TCX_1710_SHZJ].[dbo].[PR_BindingTray] GROUP BY SNum HAVING COUNT(SNum)>1) ) b)

posted @ 2019-12-05 17:29  单纯的桃子  阅读(497)  评论(0编辑  收藏  举报