--列出员工表中每个部门的员工数,和部门 no
select t.deptno,count(1) from scott.emp t group by t.deptno;
--列出员工表中每个部门的员工数(员工数必须大于 3),和部门名称
select t.deptno,t1.dname,count(1)
from scott.emp t
left join scott.dept t1 on t.deptno=t1.deptno
group by t.deptno,t1.dname
having count(1)>3;
--找出工资比 ward 多的员工
select a.* from scott.emp a, scott.emp b
where a.sal>b.sal and b.ename='ward';
--列出所有员工的姓名和其上级的姓名
select a.empno,a.ename,a.mgr,b.empno,b.ename from scott.emp a, scott.emp b
where a.mgr=b.empno;
--以职位分组,找出平均工资最高的两种职位
select * from (select job,avg(sal) from scott.emp group by job order by avg(sal) desc )where rownum<3;
--查找出不在部门 20,且比部门 20 中任何一个人工资都高的员工姓名、部门名称
--比任何人的工资高就是比工资最高的还要高
select * from scott.emp where sal>(select max(sal) from scott.emp where deptno='20') and deptno<>'20';
--得到平均工资大于 2000 的工作职种
select job from scott.emp group by job having avg(sal)>2000;
--分部门得到 工资大于 2000 的所有员工的平均工资,并且平均工资还要大于 2500
select t.deptno,avg(sal) from scott.emp t where t.sal>2000 group by t.deptno having avg(sal)>2500;
--得到每个月工资总数最少的那个部门的部门编号,部门名称,部门位置
select * from scott.dept
where deptno = (
select c.deptno from (select deptno,sum(sal) from scott.emp group by deptno order by sum(sal)) c
where rownum=1
);
--分部门得到平均工资等级为 3 级(等级表)的部门编号
select b.dno from scott.salgrade a,
(select t.deptno as dno,avg(t.sal) as avgsal
from scott.emp t
group by t.deptno) b
where a.grade=3 and b.avgsal between a.losal and a.hisal;
--查找出部门 10 和部门 20 中,工资最高第 3 名到工资第 5 名的员工的员工名字,部门名字,部门位置
select * from (select rownum no,b.* from (select a.* from scott.emp a where a.deptno in(10,20) order by a.sal desc) b) c
where c.no>=3 and c.no<=5;
select c.ename,d.dname,d.loc from (select rownum no,b.* from (select a.* from scott.emp a where a.deptno in(10,20) order by a.sal desc) b) c,scott.dept d
where c.deptno=d.deptno and c.no>=3 and c.no<=5;
--查找出收入(工资加上奖金),下级比自己上级还高的员工编号,员工名字,员工收入
select a.empno,a.ename,a.sal+nvl(a.comm,0) from scott.emp a,scott.emp b
where a.mgr=b.empno and (a.sal+nvl(a.comm,0))>(b.sal+nvl(b.comm,0));
--查找出工资等级不为 4 级的员工的员工名字,部门名字,部门位置
select c.ename,c.deptno,d.loc,c.sal from scott.dept d,
(select a.ename,a.deptno,a.sal from scott.emp a,scott.salgrade b
where b.grade<>4 and a.sal between b.losal and b.hisal) c
where d.deptno=c.deptno;
--查找出职位和'MARTIN' 或者'SMITH'一样的员工的平均工资
select avg(sal) from scott.emp where job in (select job from scott.emp where ename in('MARTIN','SMITH')) group by job;
--查找出不属于任何部门的员工
select * from scott.emp where deptno is null or deptno not in(select deptno from scott.dept);
--按部门统计员工数,查处员工数最多的部门的第二名到第五名(列出部门名字,部门位置)
select c.dname,c.loc from (select rownum no,a.* from(select t.deptno,count(1) from scott.emp t group by t.deptno order by count(1) desc) a)b ,scott.dept c
where b.deptno=c.deptno and b.no>=2 and b.no<=5;
--查询出 king 所在部门的部门号\部门名称\部门人数
select b.deptno,a.dname,b.count from scott.dept a,
(select deptno,count(1) as count from scott.emp
where deptno in(select deptno from scott.emp where ename = 'KING') group by deptno) b
where a.deptno=b.deptno;
select b.deptno,a.dname,b.count from scott.dept a,
(select deptno,t.count from(select deptno,count(1) as count from scott.emp group by deptno) t
where t.deptno in(select deptno from scott.emp where ename = 'KING')) b
where a.deptno=b.deptno;
select a.deptno 部门号,a.dname 部门名称,(select count(*) from scott.emp where deptno in (select deptno from scott.emp where ename ='KING')) 部门人数
from scott.dept a,scott.emp b where a.deptno=b.deptno and b.ename='KING';
--查询出 king 所在部门的工作年限最大的员工名字
select t.ename from(select rownum no,a.* from(select ename,hiredate from scott.emp where deptno in(select deptno from scott.emp where ename='KING') order by hiredate) a) t
where t.no=1;
--查询出工资成本最高的部门的部门号和部门名称
select deptno,dname from scott.dept where deptno in(
select b.deptno from (select rownum no,a.* from (select deptno,sum(sal) from scott.emp group by deptno order by sum(sal) desc) a) b where b.no=1 );
分享到:
相关推荐
T型三电平+SVPWM的下垂控制与双闭环中点电位平衡控制.pdf
STM32真实企业级项目:锅炉控制器源码、原理图与PCB图.pdf
STM32F103 Modbus主站源码:正常使役,支持多从机功能码通信及从机寄存器写入.pdf
Simulink永磁同步直驱风机PMSG一次调频离散模型:含虚拟惯性与下垂控制,可扩展至光伏储能研究.pdf
VSG仿真、并网与离网运行仿真、预同期并网控制及虚拟同步机逆变器仿真.pdf
VIC水文模型全程视频教学指导.pdf
vrep_coppeliasim+matlab机器人轨迹控制仿真:利用matlab读取轨迹并控制机械臂在墙上绘图的详细学习示例.pdf
2000-2022年上市公司行业异质性数据(技术密集型、劳动密集型、资本密集型)(含原始数据和处理代码) 1、时间:2000-2022年 2、指标:股票代码、年份、股票简称、统计日期、行业名称、行业代码、成立日期、上市日期、所在省份、所在城市、上市状态、保留两位行业代码、保留一位行业代码、高科技为1,非高科技为0、重污染为1,非重污染为0、制造业为1,非制造业为0、劳动密集型为1,资本密集型为2,技术密集型为3 3、来源:csmar 4、根据2012年中国证监会行业划分是否高科技、是否重污染、是否制造业、是否劳动密集型、资本密集型、技术密集型。 5、内容:包括原始数据、处理代码和计算结果
TMS320F28335电机控制程序:BLDC、PMSM无感有感及异步VF程序源代码与开发资料大全.pdf
tc275、s12x、s32k144基于CANoe的UDS诊断数据库CDD文件及CAPL Boot上位机、下位机程序移植说明文档.pdf
STM32系列通信透传技术:以太网、串口、CAN透传及OBD协议解析.pdf
STM32开发:IIR带阻滤波器设计与实现.pdf
UG后处理:CNC西门子828D后处理与西门子后处理工厂实战自用.pdf
MYSQL深入学习总结.pdf
Stewart六自由度平台反解算法 C#.pdf
1、文件说明: Centos8操作系统vim-ale-3.3.0-1.el8.rpm以及相关依赖,全打包为一个tar.gz压缩包 2、安装指令: #Step1、解压 tar -zxvf vim-ale-3.3.0-1.el8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm
tc275、s12x和s32k144的Boot程序及UDS故障诊断与Bootloader移植的Python自制上位机源码.pdf
SSA-CNN-LSTM时间序列预测(Matlab)_ 麻雀算法优化卷积长短期记忆网络.pdf
UI篇:C#工控上位机Chart控件实现与展示.pdf
SRM12-8开关磁阻电机,功率2200w,额定转速3450rpm.pdf