代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PLSQL
】
Oracle复杂查询
作者:
Dezai.CN
/ 发布于
2012/5/21
/
877
<div> <span style="color: rgb(0,0,255)">1:列出所有员工的姓名,部门名称,和工资</span> <span style="color: rgb(153,51,0)">select a1.ename,a1.sal,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno;</span> <span style="color: rgb(0,0,255)">2:列出所有部门的详细信息和部门人数</span> <span style="color: rgb(51,51,51)">select a2.deptno,a2.dname,a2.loc,count(a1.empno) from emp a1,dept a2 where a1.deptno(+) = a2.deptno group by a2.deptno,a2.dname,a2.loc;</span> <span style="color: rgb(0,0,255)">3:列出所有员工的年工资,所在部门名称,按年薪升序排列</span> <span style="color: rgb(0,128,0)">select a1.sal*12 ,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno order by a1.sal*12;</span> <span style="color: rgb(0,0,255)">4:查出每个员工的上级主管及所在部门名称,并要求这些主管的薪水超过3000</span> <span style="color: rgb(128,0,0)">select employee.ename,boss.ename ,a1.dname from emp employee,emp boss,dept a1 where employee.mgr = boss.empno and boss.deptno = a1.deptno and boss.sal >3000;</span> <span style="color: rgb(0,0,255)">5:求出部门名称中带’S’字符的部门员工的工资合计,部门人数</span> <span style="color: rgb(255,153,204)">SELECT d.deptno,NVL(SUM(sal),0),COUNT(empno)FROM emp e,dept d WHERE e.deptno(+)=d.deptno AND d.dname LIKE '%S%' GROUP BY d.deptno ;</span> <span style="color: rgb(0,0,255)">6:列出部门名称和这些部门的员工信息(数量,平均工资),同时列出那些没有员工的部门</span> <span style="color: rgb(0,0,128)">select d.dname,avg(e.sal),count(e.empno) from emp e,dept d where e.deptno(+)=d.deptno group by d.dname;</span> <span style="color: rgb(0,0,255)">7:列出在部门”SALES”工作的员工姓名,基本工资,雇用日期,部门名称,假定不知道销售部的部门编号</span> <span style="color: rgb(0,128,0)">select a1.ename,a1.sal,a1.hiredate,a2.dname from emp a1,dept a2 where a1.deptno = a2.deptno and a2.dname = 'SALES';</span> <span style="color: rgb(0,0,255)">8:列出公司各个工资等级雇员的数量,平均工资</span> <span style="color: rgb(128,0,128)">select grade,count(*),avg(sal) from emp, salgrade where sal between losal and hisal group by grade;</span> <span style="color: rgb(0,0,255)">9:列出薪水高于在部门30工作的所有员工的薪金的员工姓名和薪金,部门名称</span> <span style="color: rgb(153,51,0)">select a1.ename,a1.sal,a2.dname from emp a1, dept a2 where a1.deptno = a2.deptno and sal > all(select sal from emp where deptno = 30);</span> <span style="color: rgb(0,0,255)">10:列出受雇日期早于直接上级的所有员工的编号,姓名,部门名称,部门位置,部门人数</span> <p align="left"><span style="color: rgb(255,102,0)">SELECT e.empno,e.ename,d.dname,d.loc,temp.count</span> <p align="left"><span style="color: rgb(255,102,0)">FROM emp e,emp m,dept d,(</span> <p align="left"><span style="color: rgb(255,102,0)">SELECT deptno dno, COUNT(empno) count</span> <p align="left"><span style="color: rgb(255,102,0)">FROM emp</span> <p align="left"><span style="color: rgb(255,102,0)">GROUP BY deptno) temp</span> <p align="left"><span style="color: rgb(255,102,0)">WHERE e.mgr = m.empno(+) AND e.hiredate < m.hiredate</span> <p align="left"><span style="color: rgb(255,102,0)">AND e.deptno = d.deptno</span> <span style="color: rgb(255,102,0)">AND e.deptno = temp.dno;</span> <span style="color: rgb(0,0,255)">11:列出所有“clerk”的姓名及其部门名称,部门人数,工资等级</span> <p align="left"><span style="color: rgb(128,0,128)">SELECT e.ename , d.dname ,temp.count,s.grade</span> <p align="left"><span style="color: rgb(128,0,128)">FROM emp e, dept d,(</span> <p align="left"><span style="color: rgb(128,0,128)">SELECT deptno dno,COUNT(empno) count</span> <p align="left"><span style="color: rgb(128,0,128)">FROM emp</span> <p align="left"><span style="color: rgb(128,0,128)">GROUP BY deptno) temp,salgrade s</span> <p align="left"><span style="color: rgb(128,0,128)">WHERE job='CLERK'</span> <p align="left"><span style="color: rgb(128,0,128)">AND e.deptno = d.deptno</span> <p align="left"><span style="color: rgb(128,0,128)">AND d.deptno = temp.dno</span> <span style="color: rgb(128,0,128)">AND e.sal BETWEEN s.losal AND s.hisal;</span> <span style="color: rgb(0,0,255)">12:列出最低薪金大于1500的各种工作及从事此工作的全部雇员人数及所在部门名称,位置,平均工资</span> <p align="left"><span style="color: rgb(0,128,0)">SELECT t.job,t.count,d.dname,e.ename,reg.avg</span> <p align="left"><span style="color: rgb(0,128,0)">FROM dept d,(</span> <p align="left"><span style="color: rgb(0,128,0)">SELECT e.job,COUNT(e.empno) count</span> <p align="left"><span style="color: rgb(0,128,0)">FROM emp e</span> <p align="left"><span style="color: rgb(0,128,0)">GROUP BY e.job</span> <p align="left"><span style="color: rgb(0,128,0)">HAVING MIN(e.sal)>1500</span> <p align="left"><span style="color: rgb(0,128,0)">)t,emp e,(</span> <p align="left"><span style="color: rgb(0,128,0)">SELECT deptno dno,AVG(sal) avg</span> <p align="left"><span style="color: rgb(0,128,0)">FROM emp</span> <p align="left"><span style="color: rgb(0,128,0)">GROUP BY deptno</span> <p align="left"><span style="color: rgb(0,128,0)">)reg</span> <p align="left"><span style="color: rgb(0,128,0)">WHERE e.deptno = d.deptno AND e.job = t.job</span> <span style="color: rgb(0,128,0)">AND e.deptno = reg.dno;</span> <span style="color: rgb(0,0,255)">13:列出薪金高于公司平均薪金的所有员工,所在部门,上级领导,公司的工资等级</span> <span style="color: rgb(255,0,0)">select a1.ename,a2.dname,a1.mgr,a3.grade from emp a1,dept a2,salgrade a3,(select avg(sal) mysal from emp) a4 where a1.deptno = a2.deptno and sal between a3.losal and a3.hisal and a1.sal > a4.mysal;</span> <span style="color: rgb(0,0,255)">14:列出与SCOTT从事相同工作的所有员工及部门名称,部门人数</span> <p align="left"><span style="color: rgb(153,51,102)">SELECT e.empno,e.ename,e.job,d.dname,temp.count FROM emp e,dept d,(SELECT deptno dno,COUNT(empno) count FROM emp GROUP BY deptno) temp</span> <span style="color: rgb(153,51,102)">WHERE e.job=(SELECT job FROM emp WHERE ename='SCOTT') AND e.ename<>'SCOTT' AND e.deptno=d.deptno AND temp.dno=e.deptno;</span> <span style="color: rgb(0,0,255)">15:列出在每个部门工作的员工数量,平均工资,和平均服务年限</span> <span style="color: rgb(0,128,0)">SELECT d.dname,count(e.empno),avg(e.sal),round(avg(sysdate-e.hiredate)/365) from emp e,dept d where e.deptno(+)=d.deptno GROUP BY d.dname;</span> <span style="color: rgb(0,0,255)">16:列出各种工作的最低工资及此雇员姓名</span> <span style="color: rgb(0,128,0)">select a1.ename,a1.job,a1.sal from emp a1,(select job,min(sal) min_sal from emp group by job) a2 where a1.job=a2.job and a1.sal=a2.min_sal;</span> <span style="color: rgb(0,0,255)">17:列出各个部门的MANAGER的最低薪金,姓名,部门名称,部门人数</span> <p align="left"><span style="color: rgb(128,0,0)">select e.sal,e.ename,d.dname, count from(<span style="color: rgb(128,0,0)">select </span>job,min(sal) sal,ename,deptno from emp where job='MANAGER'GROUP BY job,ename,deptno) e,</span> <p align="left"><span style="color: rgb(128,0,0)">(<span style="color: rgb(128,0,0)">select </span>d.deptno,d.dname,count(e.empno) count fromemp e,dept d wheree.deptno=d.deptno GROUP BY d.deptno,d.dname) d</span> <span style="color: rgb(128,0,0)">where e.deptno=d.deptno;</span> <span style="color: rgb(255,0,0)"><strong>Oracle</strong><strong>分页(根据</strong><strong>ROWNUM</strong><strong>分页)</strong></span> <span style="color: rgb(128,0,128)">select * from (select a1.*,rownum rn from (select ename,sal from emp order by sal) a1 where rownum<=10) where rn >=6;</span> </div>
试试其它关键字
Oracle复杂查询
同语言下
.
查看某张表的表结构
.
oracle 集合操作
.
for 循环中倒序 用reverse
.
Oracle 临时表空间收缩
.
查看session及其对应运行的sql
.
Oracle常用查看表结构命令
.
Oracle Connect By Prior用法(实现递归查询)
.
重置排序 SEQUENCE
.
创建一个trigger
.
批量替换字段中的字符
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3