Home >Database >Mysql Tutorial >sql面试题(查看数据中指定几行记录)_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:16:411272browse

分享一个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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn