oracle---plsql---示例laobai
select * from scott.emp;
--1 列出emp表中各部门的部门号,最高工资,最低工资
select deptno,max(sal),min(sal) from scott.emp group by deptno; 2 列出emp表中各部门job为'CLERK'的员工的最低工资,最高工资
select min(sal),max(sal) from scott.emp where job='CLERK' 3 --对于emp中最低工资小于13000的部门,
--列出job为'CLERK'的员工的 (部门号),最低工资,最高工资
select min(sal),max(sal) from scott.emp where job='CLERK' and deptno in
(
select deptno from scott.emp group by deptno having min(sal)<'13000'
) 4 根据部门号由高而低,工资有低而高列出每个员工的姓名,部门号,工资 select ename,deptno,sal from scott.emp order by deptno desc,sal 5列出'张三'所在部门中每个员工的姓名与部门号
select ename,deptno from
scott.emp where deptno in
(
select deptno from scott.emp where ename='WARD'
) 6列出每个员工的姓名,工作,部门号,部门名
select ename,job,scott.emp.deptno ,scott.dept.dname
from scott.emp inner join scott.dept on scott.emp.deptno = scott.dept.deptno; select ename,job,scott.emp.deptno ,scott.dept.dname
from scott.emp , scott.dept where
scott.emp.deptno = scott.dept.deptno; 7列出emp中工作为'CLERK'的员工的姓名,工作,部门号,部门名
select ename,job,scott.emp.deptno ,scott.dept.dname
from scott.emp , scott.dept
where
scott.emp.deptno = scott.dept.deptno and job='CLERK'; 8 对于emp中有管理者的员工,列出姓名,管理者姓名(管理者外键为mgr)
同表自关联。适合于设计多级菜单,多级种类。
select s1.ename,s2.ename as 管理者
from
(select * from scott.emp where mgr is not null) s1,scott.emp s2
where s1.mgr = s2.empno; 9对于dept表中,列出所有部门名,部门号,
select * from
同时列出各部门工作为'CLERK'的员工名与工作
select d.*,e.ename,e.job from scott.dept d join
(select deptno,ename,job from scott.emp where job='CLERK') e
on d.deptno = e.deptno; 10 对于工资高于本部门平均水平的员工,列出部门号,姓名,工资,按部门号排序
select deptno,ename,sal from scott.emp e
where sal>(select avg(sal) from scott.emp where deptno = e.deptno)
order by deptno; select deptno,avg(sal) from scott.emp group by deptno 11 对于emp,列出各个部门中工资高于本部门平均水平的员工数和部门号,
按部门号排序
select count(1) 员工数,deptno from
( select deptno,ename,sal from scott.emp e
where sal>(select avg(sal) from scott.emp where deptno = e.deptno)
) group by deptno order by deptno; 12 对于emp中工资高于本部门平均水平,人数多与1人的,列出部门号,人数,按部门号排序
select count(1) 员工数,deptno from
( select deptno,ename,sal from scott.emp e
where sal>(select avg(sal) from scott.emp where deptno = e.deptno)
) group by deptno having count(1)>1 order by deptno; 13 对于emp中低于自己工资至少5人的员工,列出其部门号,姓名,工资,
[以及工资少于自己的人数]
--找出有比自己工资少的人
select t.* from
(
select deptno,ename,sal,empno from scott.emp
where sal not in
(
select sal from (
select distinct(sal) ,rownum r from scott.emp order by sal )
where r<6
)
) t ,scott.emp where scott.emp.sal<t.sal; select a.deptno,a.ename,a.sal,(select count(b.ename) from
emp as b where b.sal<a.sal) as 人数 from scott.emp as a
where (select count(b.ename) from emp as b where b.sal<a.sal)>5
oracle---plsql---示例laobai的更多相关文章
- oracle 存储过程 示例
oracle 存储过程 示例 CreationTime--2018年9月4日09点49分 Author:Marydon 1.情景展示 对VIRTUAL_QRCODELOG表的静态二维码,动态二维码 ...
- Oracle/PLSQL: ORA-06550
参考: http://blog.csdn.net/haiross/article/details/20612135 Oracle/PLSQL: ORA-06550 Learn the cause an ...
- Oracle 游标示例,带异常处理
Oracle游标示例一则,带异常处理. DECLARE CURSOR c_dl IS SELECT ID, NSRSBH, WSPZXH, ZXYY_DM, HZRQ, SWJG_DM, GXSJ F ...
- Oracle PLSQL读取(解析)Excel文档
http://www.itpub.net/thread-1921612-1-1.html !!!https://code.google.com/p/plsql-utils/ Introduction介 ...
- MyEclipse+Weblogic+Oracle+PLSQL配置注意事项
Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...
- oracle Plsql 运行update或者delete时卡死问题解决的方法
oracle Plsql 运行update或者delete时 遇到过Plsql卡死问题或者导致代码运行sql的时候就卡死. 在开发中遇到此问题的时候,本来把sql复制出来,在plsql中运行,Sql本 ...
- oracle plsql基本语法
oracle plsql 基本语法 --plsql默认规则:plsql赋值用":=" plsql判断用"=" plsql输入用"&" ...
- Oracle/PLSQL存储过程详解
原文链接:https://blog.csdn.net/zezezuiaiya/article/details/79557621 Oracle/PLSQL存储过程详解 2018-03-14 17:31: ...
- Oracle PLSQL
Oracle :show explain plan select * from table(dbms_xplan.display); EXPLAIN PLAN FOR statements In fa ...
- 本地不安装Oracle,plsql远程连接数据库
由于Oracle的庞大,有时候我们需要在只安装Oracle客户端如plsql.toad等的情况下去连接远程数据库,可是没有安装Oracle就没有一切的配置文件去支持.最后终于发现一个很有效的方法,Or ...
随机推荐
- SQL SERVER作业的Schedules浅析
SQL SERVER作业的计划(Schedules),如果你没仔细研究过或没有应用一些复杂的计划(Schedules),那么你觉得SQL SERVER作业的计划(Schedules)非常好用,也没啥问 ...
- Shell十三问[转]
Shell十三问 转载于网络,稍加整理. (一) 为何叫做Shell? 我们知道计算机的运作不能离开硬件,但使用者却无法直接对硬件作驱动,硬件的驱动只能透过一个称为"操作系统(Operati ...
- Mysql错误:Ignoring query to other database解决方法
Mysql错误:Ignoring query to other database解决方法 今天登陆mysql show databases出现Ignoring query to other datab ...
- Java 6 JVM参数选项大全(中文版)
原文来自: http://kenwublog.com/docs/java6-jvm-options-chinese-edition.htm 本文是基于最新的SUN官方文档Java SE 6 Hotsp ...
- [No000068]document.body.clientHeight 和 document.documentElement.clientHeight 的区别
document.body.clientWidth ==> BODY对象宽度 document.body.clientHeight ==> BODY对象高度 document.docume ...
- 适配iOS10的哪些事 ---- 学习笔记八
一. 上传了一个版本,为什么没有构建版本? 解:info.plist中的Bundle version 与上一个版本一致或少于上一个版本,上线新版本时,Bundle version和Bundle ... ...
- android第一行代码-5.监听器的两种用法和context
监听器的两种用法 1.匿名函数设置监听器 public class MainActivity extends Activity { private Button button; @Override p ...
- HttpClient
Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且 ...
- event.srcElement ,event.fromElement,event.toElement
自然,我们都习惯了 IE,在 IE 中要在函数中获得各事件对象很容易,直接用 event.event.srcElemtn.event.fromElement.event.toElement 就行了.在 ...
- Spring Security(08)——intercept-url配置
http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...