SELECT *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY ProductCode) AS Num,
ProductName
FROM BASE_Product
WHERE IsActive = 1) BASE_Product
WHERE Num > 0
AND Num < (21)
--------------------------------------------------------------------------------
-- ② Integers table
--------------------------------------------------------------------------------
with
p0(i) as (select 1 union all select 1 union all select 1 union all select 1)
, p1(i) as (select 1 from p0 as a, p0 as b, p0 as c, p0 as d, p0 as e)--1K rows
select row_number() over(order by i) as val
into integers
from p1;
GO
1024 行受影响
select top 25 *
from integers
where (val - 1) % 4 = 0
GO
为此,您可以使用Modulo运算符。
在这种情况下:
我已经设置了一个样本,生成了一系列 1K 整数。
dbfiddle在这里
添加另一个条件
或者简单地列出所有值: