用row_number() over 优化分页查询

SELECT * FROM (
SELECT t.*,row_number() over(ORDER BY n_count DESC) r
FROM t_51xit t
ORDER BY t.n_count DESC
) t
WHERE r BETWEEN 4 AND 6

当查询大表时,特别是当查询结果再写查询语句时,这种写法比下面这种快n倍

SELECT * FROM (
SELECT t.*
FROM t_51xit t
ORDER BY t.n_count DESC
) t
WHERE rumrow between 4 and 6

你可能感兴趣的:(分页,row_number())