DB2 貌似没有mysql的limit语句支持,但可以通过嵌套查询实现,如:
SELECT * FROM(
SELECT B.*, ROWNUMBER() OVER() AS RN FROM
(
SELECT * FROM <TABLE_NAME>
) AS B
)AS A WHERE A.RN BETWEEN <START_NUMBER> AND <END_NUMBER>
通过rownumber函数,进行分页查找
假设你的表名字为t1,其中有一个字段为id,你打算按照id的升序排列,依次显示1-5条、6-10条等SELECT * FROM
(SELECT *, ROW_NUMBER() OVER(ORDER BY id) as r FROM t1)
WHERE r BETWEEN 1 AND 5
ORDER BY id
需要显示第m到第n条,只需替换BETWEEN和AND后面的数即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)