Derby数据库如何返回指定行数

在国内搜索网站竟然没搜到使用Derby数据库时,如何像MysqllimitOraclerownum一样的限制条件查询。

查了下官网,我直接放下面了,做一名合格的搬运工。

Sometimes it is useful to limit the number of rows that are returned from a query. This can be especially useful when querying very large tables.

The Apache Derby database uses the fetch first n rows syntax to limit rows returned from a query. Substiture a numeric value for “n” when writing the query. Listed below are examples of limiting rows with the Derby database:

Example 1: Returning the first 10 rows from a table called employee:

select * from employee fetch first 10 rows only;

Example 2: Returning the first 10000 rows from a table called employee and only selecting a subset of columns:

select fname, lname from employee fetch first 10000 rows only;

Derby also supports a ROW_NUMBER() function as of version 10.4. The ROW_NUMBER() function allows the user to query for sections of a table. Listed below is an example:

SELECT * FROM ( 
    SELECT ROW_NUMBER() OVER() AS rownum, employee.* 
    FROM employee 
) as TMP
WHERE rownum > 1 AND rownum <= 5; 

拿去不谢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值