我见过许多分页的例子,如下所示。但是,我想对许多不同的表使用相同的查询。有没有办法使用这种技术,而无需指定列名称。理想情况下,某种方式选择*以及添加的row_number列?
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY ColumnName1 ASC) AS rownumber, ColumnName1, ColumnName2
FROM TableName
) AS foo
WHERE rownumber BETWEEN 10 AND 20
答案 0 :(得分:1)
您需要在分析函数中指定要排序的列。然而,除此之外,你可以做到
SELECT *
FROM (SELECT t.*,
row_number() over (order by column1 ASC) rnk
FROM tableName t)
WHERE rnk BETWEEN 10 and 20