我在表格中有大约一百万行数据。我想删除最后3行的每5行。
示例:
Row1
Row2
Row3
Row4
Row5
Row6
Row7
Row8
Row9
Row10
删除后,它应如下所示:
Row1
Row2
Row6
Row7
我该怎么做?
答案 0 :(得分:0)
这应该这样做,但您需要在order by
中指定一些列。
并且应该有一些其他规则来删除这些记录。
DROP TABLE _test
GO
create table _test
(id int identity(1,1)
,x int
)
GO
insert into _test(x)
select 1
go 50
;with cte as (
select [rwn] = row_number() over(partition by 1 order by id)
from _test
)
delete from cte
where 1=1
and rwn%5 not in (1,2)
select * from _test
答案 1 :(得分:0)
使用此声明。它是作品
delete from temp12 where Reg_No in (select Reg_No from
(select Reg_No,Name, Row_number() over (order by reg_no) abc from temp12 )
where abc like '%3' or abc like '%4' or abc like '%5' or abc like '%8' or abc like '%9' or abc like '%0')