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. Tomcat启动找不到JRE_HOME的解决方法

    在配置测试环境时,将生产服务器的Tomcat目录打包过来后解压后,启动Tomcat后,发现如下问题: [tomcat@gsp bin]$ ./shutdown.sh Using CATALINA_BA ...

  2. Java实现不同的WebService 调用方式

    请求过程分析: 1.使用get方式获取wsdl文件,称为握手 2.使用post发出请求 3.服务器响应成功 几种监听工具: http watch Web Service explorer eclips ...

  3. SpringMVC 文件上传

    @RequestMapping("/testFileUpload") public String testFileUpload(@RequestParam("desc&q ...

  4. .NET/ASP.NET MVC(模块化开发AraeRegistration)

    阅读目录: 1.开篇介绍 2.AreaRegistration注册路由(传递路由上下文进行模块化注册) 1]开篇介绍 ASP.NET Routing 路由功能非常强大,设计的也很巧妙:如果说ASP.N ...

  5. Jquery操作cookie,实现简单的记住用户名的操作

     一.jquery.cookie.js介绍  jquery.cookie.js是一个基于jquery的插件,一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cook ...

  6. grub2挂在iso镜像“ /dev/disk/by-label/XXXX error: boot device didn't show up after 30 seconds”问题

    两种解决办法: 方法A: mkdir /cdrom mount -t vfat /dev/sda1 /cdrom modprobe loop losetup /dev/loop6 /cdrom/boo ...

  7. [转]如何在ASP.NET Core中实现一个基础的身份认证

    本文转自:http://www.cnblogs.com/onecodeonescript/p/6015512.html 注:本文提到的代码示例下载地址> How to achieve a bas ...

  8. 第3章 Linux常用命令(2)_权限管理命令

    2. 权限管理命令 2.1 改变文件或目录权限:chmod (1)chmod命令 命令名称 chmod(change the permission mode of a file) 命令所在路径 /bi ...

  9. [备份]破解Xamarin

    [转]试用了一阵子Mono For Android,今天到期了,,囊中羞涩,只好破解. 说是要在vs2013的英文界面下运行破解包,不知道是真是假,下载并安装了一个. 然后又下载了破解包.是个名为xa ...

  10. 通过trie树实现单词自动补全

    /** * 实现单词补全功能 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #incl ...