例如:
pageSize=10; //条页显示10条记录
page=1;      //当前页
select top pageSize id from product where sign=0
and id not in(select top (page-1)*pageSize from product
where sign=0 order by id desc) order by id desc现在这样的话是查询到了一批含有10 条记录的数据。
但是往往有些时候还得知道符合这个条件的共有多少条记录,
所以我想问下大家有没有办法让上面这条SQL语句中顺便查出符合条件的共有多条记录。 我的目的是想在一条SQL语句中实现这样的功能。

解决方案 »

  1.   

    select count(*) as all top pageSize id from product where sign=0
    and id not in(select top (page-1)*pageSize from product
    where sign=0 order by id desc) order by id desc
    count(*)就是查总记录数,给它定义个别名,这么在外面好取出来用
      

  2.   

    那as all 中的"all" 是总记录数的别名吗
      

  3.   

    是没有结果是吧,那你先试下这个,先看看能不能查出总数
    select count(*) from product where sign=0
    and id not in(select top (page-1)*pageSize from product
    where sign=0 order by id desc) order by id desc
    建议用两句好了