Derby DB SQL,从行号开始选择行 [英] Derby DB SQL, Select Rows starting from row number

查看:74
本文介绍了Derby DB SQL,从行号开始选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在derby的SQL中选择从X行到Y行?

How can I select From X rows to Y rows in a SQL in derby?

例如:


  • 我想选择第15-30行,而不是前15行。

  • 选择从第30行开始的所有行。

我尝试了LIMIT和ROWNUM不起作用,如何在德比中做到这一点?

I tried LIMIT and ROWNUM do not work, how can I do it in derby?

推荐答案

根据 常见问题解答

According to the FAQ:


Derby不支持LIMIT语法。但是,Derby 10.4添加了ROW_NUMBER函数,Derby 10.7添加了OFFSET和FETCH子句。

Derby does not support the LIMIT syntax. However, Derby 10.4 added the ROW_NUMBER function and Derby 10.7 added the OFFSET and FETCH clauses.

Derby还支持限制通过JDBC查询返回的行数。 >
< ...>

Derby also supports limiting the number of rows returned by a query through JDBC.
<...>

从10.4.1.3版本开始,Derby还支持使用ROW_NUMBER函数限制行数。

< ...>

Starting with the 10.4.1.3 release Derby also supports limiting the number of rows using the ROW_NUMBER function.
<...>

ROW_NUMBER函数还可用于选择从偏移量开始的有限行,例如:

< ...>

The ROW_NUMBER function can also be used to select a limited number of rows starting with an offset, for example:
<...>



SELECT * FROM ( 
    SELECT ROW_NUMBER() OVER() AS rownum, myLargeTable.* 
    FROM myLargeTable 
) AS tmp 
WHERE rownum > 200000 AND rownum <= 200005; 






如果您使用的是Derby 10.7或更高版本,则可以,也请使用 OFFSET和FETCH子句


If you are using Derby 10.7 or newer you can, also, use the OFFSET and FETCH clauses:

SELECT * FROM T ORDER BY I 
    OFFSET 10 ROWS 
    FETCH NEXT 10 ROWS ONLY

这篇关于Derby DB SQL,从行号开始选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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