access数据库取中间某段记录
Select Top n-m+1 * From Table Where Id>(Select Max(Id) From (Select Top m-1 Id From Table order By Id Asc) Temp) order By Id Asc
从TABLE表中取出第m到n条记录 (Exists版本)
Select TOP n-m+1 * FROM TABLE AS a Where Not Exists(Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id ) order by id
select * from table_name where id_field not in (select top 3 id_field from table_name) |
注意,其实就是把 select top 语句写两遍,第二遍包含了第一遍,然后把是第一遍中的记录用not in剔除就可以了,所以两个where都必须包含相同的外加条件。
asp 中经常用来写 pageno 的程序,因为直接用ado的pagesize如果遇上几十万数据,用pagesize就完蛋喽。
关于 not in 语句速度比较慢,某人提示将not in改为
select table2.* from table2 left join table1 on table2.key=table1.key where (able1.key is null) |
返回第3条记录用:
select top 1 * from (Select top 3 a.编号 FROM a order by 编号) as b order by 编号 desc |
如果用来进行分页,返回第100-150条记录,可以用
select top 50 * from (Select top 150 a.编号 FROM a order by 编号) as b order by 编号 desc |
以下是 SQL SERVER 2000 T-SQL 分页代码
-------------------------- -- 分页代码
IF EXISTS (Select name Create PROCEDURE p_GetTopic -- ============================================= |
版权声明:
作者:Kiyo
链接:https://www.wkiyo.cn/html/2009-08/i602.html
来源:Kiyo's space
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论