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 2012链接到SQL SERVER 2000的问题解决案例
前几天在在桦仔的SQLSERVER走起微信公众帐号看到一篇文章MS SQL Server2014链接MS SQL Server 2000,当时手机上囫囵吞枣看了个大概,知道是由于SQL SERVER ...
- 作业配置规范文档[MS SQL]
作业配置规范文档(MS SQL) 文档类型 MS SQL数据库作业配置规范文档 创建日期 2015-07-30 版本变化 V3.0 修改记录 修改人 修改日期 版本 修改描述 潇湘隐者 2015-08 ...
- Why Do We Need a Data Warehouse?
https://dwbi1.wordpress.com/2012/12/03/why-do-we-need-a-data-warehouse/ 经常有人来质疑数据仓库的价值,为什么我们需要花费一年多的 ...
- ora-01033和ora-12560错误的解决方案
1.登录pl sql 报01033的错误,如下图: 2.登录cmd中,报12560的错误,如下图: 3.查看服务和注册表都没有问题,如下: 查看服务,已启动,如下图: 运行regedit,进入HKEY ...
- List tuple 类型转成数组
SKlearning大部分的输入数据都是M * N数组. 然而我们从数据库或文件读取得来的通常是Python内定的类型tuple或list 它们的优势就不说了,但是直接把list或tuple构成的二维 ...
- 【转】hive优化之--控制hive任务中的map数和reduce数
一. 控制hive任务中的map数: 1. 通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置 ...
- css div中内容绝对居中(多行内容)
div中的内容绝对居中(不适合IE6哦,IE6我已经不考虑了),直接看代码吧. <!DOCTYPE HTML> <html> <head> <title> ...
- WSTMall网站系统最新官方版
WSTMall V1.0是在thinkphp 的经典版本3.2.2基础上进行优化开发的, TP 3.2.2不是thinkphp的一个最新的版本,却是thinkphp最金典的一个版本,正所谓站在巨人的肩 ...
- 【2016-10-25】【坚持学习】【Day12】【WPF】【Telerik】【VirtualtionData 虚拟化数据】
VirtualQueryableCollectionView When working with the UI components that enable UI Virtualization, yo ...
- Linux 之 GCC 和 GDB
1 GCC = GNU C Compiler 1) pre-processing (预处理) $ gcc -E -o hello.i hello.c // -E 预处理后停止 2) compil ...