SQL分页语句

万能分页:
select top 每页显示的记录数 * from topic where id not in  
 (select top (当前的页数-1)×每页显示的记录数 id from topic order by id desc)   
 order by id desc 


SQL2005中的分页代码:
with temptbl as (   
  SELECT ROW_NUMBER() OVER (ORDER BY id desc)AS Row,    
  ...   
)   
SELECT * FROM temptbl where Row between @startIndex and @endIndex  


我的分页定义:
SELECT TOP $ROW_SIZE $COLS FROM $TABLE_NAME WHERE $PRIMARY_KEY NOT IN (SELECT TOP $TOP_NUM $PRIMARY_KEY FROM $TABLE_NAME ORDER BY $PRIMARY_KEY $SORT) ORDER BY $PRIMARY_KEY $SORT

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