sql三种分页分析

 1.分页方案一:(利用Not In和SELECT TOP分页)

  语句形式:

SELECTTOP 页大小*
FROM TestTable
WHERE(ID NOT IN
     (SELECT TOP 页大小*页数 id
       FROM 表
       ORDERBY id))
ORDERBY ID

 

(Sql2000 Northwind.Customers表)

select  top 10 *
from customers
where (customerId not in (select top 20 customerId from customers order by customerId))
order by customerId

(查询第二页,每页10条数据)

 

2.分页方案二:(利用ID大于多少和SELECT TOP分页)

  语句形式:

  SELECT TOP 10 *
   FROM TestTable
   WHERE(ID > (SELECT MAX(id)
            FROM(SELECT TOP 20 id
              FROM TestTable
              ORDERBY id)

               AST)

        )
   ORDERBY ID


SELECTTOP页大小*
FROMTestTable
WHERE(ID>
     (SELECTMAX(id)
    FROM(SELECTTOP页大小*页数id
        FROM表
        ORDERBYid)AST))
ORDERBYID

你可能感兴趣的:(sql,sql)