标签:des style sp on 数据 bs as new sql
在"评论表Reply(reID,reContent)"中,reID是自增列,但Reply表中的数据被删除过,即reID不是连续的。
1):请用一条SQL语句找出排在倒数100~120位置的那20条数据,按reID降序排列
1, Select * from ( select top(100) from ( Select top(120) * from bbb desc)) desc
2,Select row_number() over(order by reid) as id ,reid,recontent from reply where id between 100 and 120
第二种好用,但是sqlserver2000没得用
2):假设Reply中只被删除过1条记录,请找出被删除的记录的reID
Select top(1) from Select row_number() over(order by reid) as id ,reid,recontent from reply where id=reid desc
标签:des style sp on 数据 bs as new sql
原文地址:http://www.cnblogs.com/zhanying/p/4129663.html