用SQL语句检索Table表中第31-40条记录,应该怎么写?
来源:百度知道 编辑:UC知道 时间:2024/06/24 17:21:04
用一条SQL语句写出才可以.
select * from
(
select top 10 * from
(
select top 40 * from table order by id asc --首先得到前40条记录
) a order by id desc --得到40到31的记录
) b order by id asc --重新排序,得到31-40的记录
select top 31 * from
(select top 40 * from admin order by id) a
order by id desc
假设table的主键为ID,则可以这样写:
select top 40 * from table where ID not in(select top 30 ID from table order by ID) order by ID
如果在VFP中,可以使用其RECNO()来写出相应命令。
SELECT * FROM TableName WHERE RECNO()>=31 AND RECNO()<=40
而标准的SQL语言中,记录不分先后顺序,似乎不大好整得。