标签:one use select ide sql 分页 where lock hid
说明:分页显示在实际业务中经常需要用到,其SQL语句分两种
--方法一:跳过多少行,选中多少行 --每页n条,选择第m页--n=2 m=3 --select top(n) * from 表 where 主键 not in (select top(m-1)*n 主键 from 表); select * from UserInfo select top(2) * from UserInfo where Empid not in (select top((3-1)*2) EmpId from UserInfo); --方法二,通过rowNumber函数,但是只能当作临时表 select * from(select * ,ROW_NUMBER() over (order by EmpId) as num from UserInfo) as T where T.num between (3-1)*2+1 and 3*2; --over开窗函数的的另一个用法 select top(2) * ,AVG(StuAge) over() as 平均年龄 from UserInfo;
标签:one use select ide sql 分页 where lock hid
原文地址:http://www.cnblogs.com/YK2012/p/6817105.html