随笔-16  评论-84  文章-1  trackbacks-0

Here i take jobs table of pubs databse for example,details as follow: 

select top eachpage *  from  jobs where job_id not in ( select top (eachpage*(currentpage-1))  job_id from jobs order by job_id desc)) order by job_id desc;

explain:
1. eachpage : the number of each page show the recorder
2.currentpage: current page

notice:
the red line in the sentence,you should take care of it, because Microsoft SQLServer  TOP Function can't support the expression .it can only support a number.
so before you prepare to buildup the sql sentence ,you should alread calculate the result of the expression about (eachpage*(currentpage-1))  .

Example:
set  eachpage=3
      currentpage=5
 so  (eachpage*(currentpage-1)) =12
select top 3 * from jobs where (job_id not in (select top 12 job_id from jobs order by job_id desc)) order by job_id desc


posted on 2008-12-03 16:00 absolute 阅读(534) 评论(0)  编辑  收藏 所属分类: DataBase

只有注册用户登录后才能发表评论。


网站导航: