sqlServer 查询表中31到40的记录,考虑id不连续的情况
写出一条sql语句输出表UserInfo表中31到40记录(数据库为SQL Server,以自动增长的ID作为主键,注意ID可能不是连续的)?
根据题意理解:
本质就是写分页查询:
每页条数:10条;
当前页码:4页;
1 //第一种: 2 select * from 3 (select ROW_NUMBER() over(order by Id asc) as num,* from UserInfo)as u 4 where u.num 5 between 6 10*(4-1)+1 7 and 8 10*4 9 //第二种:10 select top 10 * from UserInfo 11 where Id not in12 (select top (10*3) id from UserInfo order by Id)13 order by IdView Code
新闻热点
疑难解答