SQL中怎么显示指定的记录

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:54:40
有一个表,有100条记录,如何显示出第20到第50条记录啊

"select * from table where rownum>=20 and rownum<=50 " 这是条错误的语句:
问题是:第20到第50条记录
可以这么写:【不能保证很优化】

select top 30 from table where id not in (selct top 20 id from table order by id desc) order by id desc
提取第20到50条
---------------------------------------------------------
这句语句就是提取非第一条记录的前30条记录,也就是第20---50条了.where子句是以ID字段来区分的,当然你也可以用其他的字段,但最好是主键.

$sql = 'SELECT * FROM `yoursheet` LIMIT 20, 50 ';
看你是什么语言了,我这是PHP的,如果需要其他语言,站内短信联系

我以前也经常遇到这个问题
select *
from table
where rownum>=20
and rownum<=50
有必要时可用order by

rownum是不能像这样用的

说明:选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc