冒险岛性价比职业:如何从数据库中取出第n条记录?用一句sql语句实现

来源:百度文库 编辑:高考问答 时间:2024/05/08 18:47:48
如何从数据库中取出第n条记录?用一句sql语句实现

假定你的表名为Table,你的标识列为Id

如果你的n是给定值,使用下列语句就可以:

rs.open "select top 1 * from (select top 10 * from Table order by Id asc) as tmp order by Id desc",conn,3,3

如果你的n是变量,使用下列语句:

rs.open "exec('select top 1 * from (select top " + n + " * from Table order by Id asc) as tmp order by Id desc'),conn,3,3

要看你用的是那总数据库了!
如果是ORACLE
那么
select * from TABLE_NAME
where rownum=10;