SQL的各种常用算法问题
来源:互联网 发布:淘宝关注人数最多的店 编辑:程序博客网 时间:2024/05/22 05:07
---------------------------------------------
分页算法:
---------------------------------------------
实现分页,可以使用嵌套查询,也可以使用存储过程。不过存储过程太复杂,执行效率也不一定高,
所以我就用这样的嵌套语句来实现:
SELECT TOP 页大小 * FROM TestTable
WHERE (ID >(SELECT MAX(id) FROM (SELECT TOP 页大小*页数 id FROM TestTable ORDER BY id) AS T)) ORDER BY ID
select * from (select * from scott.emp order by scott.emp.empno) where rownum<=20;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
minus
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
union all
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b where rownum<=10 ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
intersect
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select aa.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=20 ) aa
minus
select bb.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=10 ) bb
select a.empno from (select scott.emp.empno from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from (select scott.emp.empno from scott.emp where rownum<=10 order by scott.emp.empno) b;
分页算法:
---------------------------------------------
实现分页,可以使用嵌套查询,也可以使用存储过程。不过存储过程太复杂,执行效率也不一定高,
所以我就用这样的嵌套语句来实现:
SELECT TOP 页大小 * FROM TestTable
WHERE (ID >(SELECT MAX(id) FROM (SELECT TOP 页大小*页数 id FROM TestTable ORDER BY id) AS T)) ORDER BY ID
select * from (select * from scott.emp order by scott.emp.empno) where rownum<=20;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
minus
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
union all
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b where rownum<=10 ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
intersect
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select aa.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=20 ) aa
minus
select bb.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=10 ) bb
select a.empno from (select scott.emp.empno from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from (select scott.emp.empno from scott.emp where rownum<=10 order by scott.emp.empno) b;
- SQL的各种常用算法问题
- SQL的各种常用算法问题
- 常用的各种排序算法
- 常用问题的算法
- 常用问题的算法
- SQL中各种日期的算法
- 各种常用sql
- 各种常用算法
- php各种常用算法
- 各种常用排序算法
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SQL各种写法的效率问题
- SciTE Lua Scripting Extension
- 北大青鸟ACCP5.0学习资料
- 廣外通用看牌器[遊戲茶苑 鬥地主 456遊戲中心等]
- 通宵搞LVS工作一则
- 微软在盗版黑屏事件可能犯下极大的错误
- SQL的各种常用算法问题
- 破解网通封路由器的4种方法
- 在Debian Lenny中安装摄像头驱动
- 有些事是说给电脑听的...
- Android终于公布源代码
- Google Android 平台正式开源
- 微软黑屏后的十句大实话
- 自由自在
- MouseMove消息异常