在DB2中获取行 [英] Fetching rows in DB2

查看:127
本文介绍了在DB2中获取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在DB2(使用9.7版)中,可以使用以下查询选择表的前10行:

I know in DB2 (using version 9.7) I can select the first 10 rows of a table by using this query:

SELECT * 
FROM myTable
ORDER BY id
FETCH FIRST 10 ROWS ONLY

但是如何获取第11至20行?
我无法使用主键或ID来帮助我...

But how can I get, for example, rows 11 to 20? I can't use the primary key or the ID to help me...

预先感谢!

推荐答案

这是一个示例查询,将从表中获取包含状态名称,缩写等的行。

Here's a sample query that will get rows from a table contain state names, abbreviations, etc.

SELECT *
FROM (
   SELECT stabr, stname, ROW_NUMBER() OVER(ORDER BY stname) AS rownumber
   FROM states
   WHERE stcnab = 'US'
) AS xxx
WHERE rownumber BETWEEN 11 AND 20 ORDER BY stname




编辑: ORDER BY 是必要的,以确保查询执行之间行编号是一致的

ORDER BY is necessary to guarantee that the row numbering is consistent between executions of the query.

这篇关于在DB2中获取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆