我需要从行号475到948删除,因为它们是1-474行的副本。我认为,它会接近这一点,还是会有更多呢?
DELETE FROM dbo.industry WHERE row_number between 475 and 948
答案 0 :(得分:3)
可能为时已晚,但我通常会这样做
; with cte(rownum)as(
select row_number () over(partition by [Col1], [Col2] order by Col3) from [table]
)
delete from cte where rownum > 1
答案 1 :(得分:1)
DELETE FROM dbo.industry
WHERE COLUMN_NAME IN -- Choose a column name
(SELECT TOP 1000
COLUMN_NAME, -- Choose a column name
ROW_NUMBER() OVER( ORDER by COLUMN_NAME ASC) AS Row_Number
FROM dbo.industry
WHERE Row_Number BETWEEN 475 AND 948 )
COLUMN_NAME可以是您想要的表格的任何列名。
答案 2 :(得分:0)
SELECT DISTINCT *
INTO #Temp
FROM dbo.industry
DELETE FROM dbo.industry
INSERT INTO dbo.industry
SELECT *
FROM #Temp
答案 3 :(得分:0)
DELETE FROM dbo.industry WHERE dbo.industry.
REPLACE WITH PK COLUMN NAME| IN (SELECT TOP 948 dbo.industry
REPLACE WITH PK COLUMN NAME| FROM dbo.industry WHERE dbo.industry
REPLACE WITH PK COLUMN NAME| > 475 ORDER BY dbo.industry
REPLACE WITH PK COLUMN NAME|)
答案 4 :(得分:0)
这不是一个真正的答案。数据存在一些问题,使得上面的答案(虽然优秀)无关。我只是删除了表,然后从固定宽度重新导入它。这一次,我更加小心,没有重复。
答案 5 :(得分:0)
如果您尝试使用Row_Number
函数删除,则会收到
窗口函数只能出现在SELECT或ORDER BY子句中
您可以修改SQL使其包含在select子句中,如下例所示:
Delete T
From (Select Row_Number() Over(Partition By [IndustryType], [IndustryDescription] order By [ID]) As RowNumber,*
From dbo.industry) T
Where T.RowNumber > 1