我的表中有大约一百万行数据。我想删除最后 3 行中的每 5 行。
例子:
Row1
Row2
Row3
Row4
Row5
Row6
Row7
Row8
Row9
Row10
删除它们后,它应该如下所示:
Row1
Row2
Row6
Row7
我该怎么做?
我的表中有大约一百万行数据。我想删除最后 3 行中的每 5 行。
例子:
Row1
Row2
Row3
Row4
Row5
Row6
Row7
Row8
Row9
Row10
删除它们后,它应该如下所示:
Row1
Row2
Row6
Row7
我该怎么做?
这应该可以,但您需要在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
使用此语句。这是作品
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')