sql面试题(查看数据中指定几行记录)


分享一个sql数据库面试题。

问题:

表 table1,主键为 ID,ID为自动编号(ID可能不连续),要求查询第31-40行记录,请问SQL语句怎么写?

实现代码:

复制代码 代码如下:

--SQL server
select top 10 *
from
(select top 40 * from table1 order by ID) a
order by ID desc
--Oracle
select *
from
(select top 40 * from t order by ID) a
where
rownum>30


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3