数据库高级查询
来源:互联网 发布:阴茎延长手术死亡知乎 编辑:程序博客网 时间:2024/06/18 14:39
对oracle下默认的scott用户下表的操作(其中3和4,5和6解决同一个问题):
1.层次查询(上层的员工号等于当前层的老板号)
select level,empno,ename,sal,mgrfrom emp
connect by prior empno=mgr
start with mgr is null
order by 1;
2.分页查询:
select rownum,r,empno,ename,sal
from(select rownum r,empno,ename,sal
from(select rownum,empno,ename,sal from emp order by sal desc) e1
where rownum<=8) e2
where r>=5;
3.相关子查询 cpu占用:33
explain plan for
select empno,ename,sal,(select avg(sal) from emp where deptno=e.deptno) avgsa from emp e
where sal>(select avg(sal) from emp where deptno=e.deptno);
select * from table(dbms_xplan.display);
4.多表查询 cpu占用:30
explain plan for
select e.empno,e.ename,e.sal,d.avgsal
from emp e,(select deptno,avg(sal) avgsal from emp group by deptno) d
where e.deptno=d.deptno and e.sal>d.avgsal;
explain plan for
select count(*) Total,
sum(decode(to_char(hiredate,'yyyy'),1980,1,0)) "1980",
sum(decode(to_char(hiredate,'yyyy'),1981,1,0)) "1981",
sum(decode(to_char(hiredate,'yyyy'),1982,1,0)) "1982",
sum(decode(to_char(hiredate,'yyyy'),1987,1,0)) "1987"
from emp;
6.伪表、子查询 cpu占用:17
explain plan for
select
(select count(*) from emp) Total,
(select count(*) from emp where to_char(hiredate,'yyyy')='1980') "1980",
(select count(*) from emp where to_char(hiredate,'yyyy')='1981') "1981",
(select count(*) from emp where to_char(hiredate,'yyyy')='1982') "1982",
(select count(*) from emp where to_char(hiredate,'yyyy')='1987') "1987"
from dual;
7.函数:
wm_concat(s.stu_name):结果用逗号隔开
where instr(a,b)>0 :返回字符串b在a中的位置,无则为0
阅读全文
0 0
- 数据库高级查询设计
- sql数据库高级查询
- 数据库查询--高级议题
- 数据库之高级查询
- 数据库高级查询
- 数据库_SQL高级查询
- 数据库高级查询
- shell操作数据库:高级查询
- 高级查询和连接数据库
- 数据库高级查询题目集
- 【Oracle数据库】高级子查询
- Oracle数据库高级查询案例
- SQL Server 数据库设计和高级查询
- SQLServer数据库设计和高级查询
- MongoDB 数据库操作(三)-高级查询
- Sql Server数据库设计和高级查询
- Sqlserver 数据库高级查询和设计
- Laravel框架学习(数据库高级查询)
- 004 Django学习之urls(Python2.7)
- Google Chrome 独立安装下载
- 用户权限管理之权限过滤
- Java集合实现斗地主功能
- 整数划分问题
- 数据库高级查询
- 自动检测两棋盘格中的角点,并计算视差How to solve Disparity
- 1088:发工资了
- 通过cmd连接远程oracle sqlplus GIS/GIS@192.168.1.137:1521/ggts
- java:MyEclipse10的安装与配置
- 文通科技汽车VIN码识别软件—你造吗!
- 利用gSoap开发Web Service C/C++客户端
- 机器学习实战之 第10章 K-Means(K-均值)聚类算法
- BZOJ 2007 浅谈对偶图优化网络流