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的更多相关文章

  1. oracle 存储过程 示例

      oracle 存储过程 示例 CreationTime--2018年9月4日09点49分 Author:Marydon 1.情景展示 对VIRTUAL_QRCODELOG表的静态二维码,动态二维码 ...

  2. Oracle/PLSQL: ORA-06550

    参考: http://blog.csdn.net/haiross/article/details/20612135 Oracle/PLSQL: ORA-06550 Learn the cause an ...

  3. Oracle 游标示例,带异常处理

    Oracle游标示例一则,带异常处理. DECLARE CURSOR c_dl IS SELECT ID, NSRSBH, WSPZXH, ZXYY_DM, HZRQ, SWJG_DM, GXSJ F ...

  4. Oracle PLSQL读取(解析)Excel文档

    http://www.itpub.net/thread-1921612-1-1.html !!!https://code.google.com/p/plsql-utils/ Introduction介 ...

  5. MyEclipse+Weblogic+Oracle+PLSQL配置注意事项

    Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...

  6. oracle Plsql 运行update或者delete时卡死问题解决的方法

    oracle Plsql 运行update或者delete时 遇到过Plsql卡死问题或者导致代码运行sql的时候就卡死. 在开发中遇到此问题的时候,本来把sql复制出来,在plsql中运行,Sql本 ...

  7. oracle plsql基本语法

    oracle plsql 基本语法 --plsql默认规则:plsql赋值用":=" plsql判断用"=" plsql输入用"&" ...

  8. Oracle/PLSQL存储过程详解

    原文链接:https://blog.csdn.net/zezezuiaiya/article/details/79557621 Oracle/PLSQL存储过程详解 2018-03-14 17:31: ...

  9. Oracle PLSQL

    Oracle :show explain plan select * from table(dbms_xplan.display); EXPLAIN PLAN FOR statements In fa ...

  10. 本地不安装Oracle,plsql远程连接数据库

    由于Oracle的庞大,有时候我们需要在只安装Oracle客户端如plsql.toad等的情况下去连接远程数据库,可是没有安装Oracle就没有一切的配置文件去支持.最后终于发现一个很有效的方法,Or ...

随机推荐

  1. JS实现HTML标签转义及反转义

    今天我用ueditor时候遇到一个问题: 我从数据库中读取内容进行编辑的时候,不是有一些html标签嘛,从数据库读出来没有问题: 但是我用asp.net mvc,把读取出来的内容通过ueditor的a ...

  2. 实时事件统计项目:优化solr和morphline的时间字段

    morphline优化,如下: 传过来的时间戳被复制到3个字段:eventTimeInMinuteChina_tdt ,eventTimeInMinuteUTC_tdt ,eventTimeInHou ...

  3. JS导出PDF插件(支持中文、图片使用路径)

    在WEB上想做一个导出PDF的功能,发现jsPDF比较多人推荐,遗憾的是不支持中文,最后找到pdfmake,很好地解决了此问题.它的效果可以先到http://pdfmake.org/playgroun ...

  4. java中对象产生初始化过程

    以前面试的时候,很多公司的笔试题中有关new一个对象有关一系列初始化的过程的选择题目.请看下面的题目. class Parent { static { System.out.println(" ...

  5. [bootstrap]bootstrap2如何引导div垂直居中

    参考网址:http://www.4byte.cn/question/138712/bootstrap-how-to-center-vertical.html 部分参考自上面网页中的方法.用过boots ...

  6. Leetcode: word search

    July 6, 2015 Problem statement: Word Search Given a 2D board and a word, find if the word exists in ...

  7. C 语言中 setjmp 和 longjmp

    在 C 语言中,我们不能使用 goto 语句来跳转到另一个函数中的某个 label 处:但提供了两个函数——setjmp 和 longjmp来完成这种类型的分支跳转.后面我们会看到这两个函数在处理异常 ...

  8. postman使用之三:API请求和查看响应结果

    请求 postman支持很多请求类型,界面左侧可以看到请求类型:get.post.put.patch等,右侧是发送和保存按钮,下方是请求支持的认证方式.信息头.信息体.私有脚本和测试结果.下面我们介绍 ...

  9. 【JavaScript Demo】回到顶部功能实现

    随着网站的不断发展,需要展示的内容也越来越丰富,这导致网页上能展示的内容越来越多.当内容堆积影响了用户体验,就需考虑如何提升用户体验.在这一系列的改动中,“回到顶部”的功能成为了一个经典. 1.页面布 ...

  10. 【读书笔记《Bootstrap 实战》】6.单页营销网站

    我们已经掌握了很多实用 Bootstrap  的重要技能.现在,是时候拿出更多的创意来帮助客户实现他们全方位在线营销的愿望了.此次将带领大家做一个漂亮的单页高端营销网站. 主要任务如下: □ 一个大型 ...