以下是使用虚拟概念的查询,但我希望它的优化形式不使用“虚拟表” 概念。
with TEMP AS
(
Select RN from
(
SELECT TCTITL,
ROW_NUMBER() OVER ( ORDER BY TCTITL asc ) AS RN FROM PVTC ORDER BY
TCTITL asc
)T
WHERE ((TCTITL >= 'AAPS ' ))
ORDER BY TCTITL asc fetch first row only )
, mytab as
(
Select * from
(
( SELECT TCTITL, TCEDUR, TCSTZF, TCTTLE, TCLSHN, TCCEQ3,
ROW_NUMBER() OVER ( ORDER BY TCTITL asc ) AS RN
FROM PVTC ORDER BY TCTITL asc )
) Q
, TEMP where Q.RN
between (TEMP.RN + 0) and ( TEMP.RN + 3)
)
select * from mytab
注意:我有一个结果为 1 到 10 的表,但我希望两个指针之间的结果只说 3 到 10。这是此查询的目标。
更新:我有五条记录,我想根据 Row_Number 2 在 1 t0 5 范围内选择记录。(其中 1,2,3,4,5 显示 Row_number )
col1 col2 col3
a b c
a1 b1 c1
-------------------------
---------------------------
--------------------------
a5 b5 c5