"select * from mailuser where status = " + ArchivingConst.ENABLED + " and id >= 0 
order by domain,username limit ?, ?";上面是在mysql中的,请问在sqlserver中如何写呢?

解决方案 »

  1.   

    假如你想按升序找出第200到第300条数据,可以这么写
    "select top 100 * from (select top 300 * from mailuser where status = " + ArchivingConst.ENABLED + " and id >= 0 order by domain,username DESC) order by domain,username ASC";
      

  2.   

    "select top ? * from mailuser where id not in(select top ? * from mailuser where status = " + ArchivingConst.ENABLED + " and id >= 0) and status = " + ArchivingConst.ENABLED + " and id >= 0  
    order by domain,username ";
    其中 id是唯一的,最好是主键
    第一个?的值小于第二个?
      

  3.   


    select   b.*   from 

      select   top   5   a.*   from   
      ( 
        select   top   10   *   from   table_name   order   by   id   asc 
      ) a   order   by   a.id   desc 
    ) b
    order   by   b.id   
      

  4.   


    select top "+pageSize+" a.*,b.userName from Bulletin a inner join UserInfo b on a.userId=b.id where a.title like '%"+keywords+"%' and a.id not in (select top "+((pageNo-1)*pageSize)+" id from Bulletin)