有没有办法从SQL Server中使用单列的表中删除重复?
是否有可能从这样的表中删除重复行而无需丢弃表并用不同的行重新创建它?
DROP TABLE IF EXISTS #temp;
CREATE TABLE #temp (id INT);
INSERT INTO #temp
VALUES (1), (2), (2), (2), (3), (3);
Is there a possible way to delete duplicate rows from a table like this without dropping the table and re-creating it with distinct rows?
DROP TABLE IF EXISTS #temp;
CREATE TABLE #temp (id INT);
INSERT INTO #temp
VALUES (1), (2), (2), (2), (3), (3);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用您正在查看的指定列分组的CTE和ROW_NUMBER可以干净地删除重复值,因为ROW_NUMBER逐步计数,并通过汇总的分区的重复值进行了重复计数。当订购时发现新的分组时,它将ROW_NUMBER重置为1,从下一个不同分组值的记录开始。
Using a CTE and ROW_NUMBER grouped by the specified column you are looking at can cleanly remove duplicate values, as ROW_NUMBER counts incrementally with duplicate values of the PARTITION BY aggregation. When a new grouping is found when ordered, it resets the ROW_NUMBER to 1 starting at that next record of different grouped values.
这是您的答案,首先我们必须找到所有重新编码,
希望您能找到最佳的解决方案。
Here is your answer, First we have to find all recodes
Hope you will find the best solutions.