select * from (
select a.*,row_number() over() as rk
from table1 tba
) as foo where rk between 11 and 20
这适用于数据库表。我正在使用一个视图,它是2个表的连接。 当我尝试做rownum时,它说:“功能不允许”
select * from (
select a.*,row_number() over() as rk
from view1 v1
) as foo where rk between 11 and 20
DB2中rownum的任何建议或替代方法吗?
答案 0 :(得分:2)
您应该在视图中加入row_number()
答案 1 :(得分:2)
正如@GregM建议的那样,将其包含在视图中的另一种方法是将其放入CTE中:
WITH numbered as (SELECT a.*, ROW_NUMBER() OVER() as rk
FROM table1 as a)
SELECT *
FROM numbered
WHERE rk BETWEEN 11 AND 20
请注意,这与原始代码一样慢(在我的版本上运行得很好)。