sqlServer-简单分页查询例子

工资从高到低排序 输出工资是第4到6行数据

1
2
3
4
select top 3 * 
from emp 
where EMPNO not in(select top 3 EMPNO from emp order by sal desc
order by sal desc

工资从高到低排序 输出工资是第13到15行数据

1
2
3
4
select top 3 * 
from emp 
where EMPNO not in(select top 12 EMPNO from emp order by sal desc
order by sal desc

总结 : 假设 每页显示n条记录,当前要显示的第m页 表名是A 主键是A_id

1
2
3
select top n* 
from
where A\_id not in(select top(m-1)*n A\_id from emp)
  • 版权声明: 本博客所有文章,未经许可,任何单位及个人不得做营利性使用!转载请标明出处!如有侵权请联系作者。
  • Copyrights © 2015-2023 翟天野

请我喝杯咖啡吧~