sql 删除SQL Server中的重复记录只保留一个

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 删除SQL Server中的重复记录只保留一个相关的知识,希望对你有一定的参考价值。

--Description: Delete Duplicate Records in SQL Server Keeping only One
--Author: Ben Thul
--Source: http://stackoverflow.com/questions/6025367/t-sql-deleting-all-duplicate-rows-but-keeping-one
--NOTE: A common use-case is that "foo, bar" are the group identifier and "baz" is some sort of time stamp. In order to keep the latest, you'd do ORDER BY baz desc)

WITH cte AS (
  SELECT[foo], [bar], 
     row_number() OVER(PARTITION BY foo, bar ORDER BY baz) AS [rn]
  FROM TABLE
)
DELETE cte WHERE [rn] > 1

以上是关于sql 删除SQL Server中的重复记录只保留一个的主要内容,如果未能解决你的问题,请参考以下文章

求教sqlserver排除颠倒重复的数据只保留1条

SQL SERVER 查询删除重复数据

SQL SERVER 查询删除重复数据

SQL SERVER怎么去掉重复数据?

SQL删除重复数据只保留一条

SQL删除重复数据只保留一条