全是自己一个一个敲出来的啊 啊 啊

 --(1)查询20号部门的所有员工信息。
select * from emp e where e.deptno=20 --(2)查询所有工种为CLERK的员工的工号、员工名和部门名。
select e.empno,e.ename,d.dname from emp e natural join dept d where e.job='CLERK' --(3)查询奖金(COMM)高于工资(SAL)的员工信息。
select * from emp e where e.sal<e.comm --(4)查询奖金高于工资的20%的员工信息。
select * from emp e where e.sal*0.2<e.comm --(5)查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息。
select * from emp e where (e.deptno=10 and e.job='MANAGER') or (e.deptno=20 and e.job='CLERK') --(6)查询所有工种不是MANAGER和CLERK,且工资大于或等于2000的员工的详细信息。
select * from emp e where e.job !='MANAGER' and e.job !='CLERK' and e.sal>2000 --(7)查询有奖金的员工的不同工种。
select distinct e.job from emp e where e.comm is not null --(8)查询所有员工工资和奖金的和。
select sum(e.sal+nvl(e.comm,0)) from emp e --(9)查询没有奖金或奖金低于100的员工信息。
select * from emp e where e.comm is null or e.comm<100 --(10)查询各月倒数第2天入职的员工信息。
select * from emp e where e.hiredate=(last_day(e.hiredate)-1) --(11)查询员工工龄大于或等于10年的员工信息。
select * from emp e where months_between(sysdate,e.hiredate)/12>=10 --(12)查询员工信息,要求以首字母大写的方式显示所有员工的姓名。
select initcap(e.ename) from emp e --(13)查询员工名正好为6个字符的员工的信息。
select * from emp e where length(e.ename)=6 --(14)查询员工名字中不包含字母“S”员工。
select * from emp e where instr(e.ename,'S')=0 --(15)查询员工姓名的第2个字母为“M”的员工信息。
select * from emp e where e.ename like '_M%' --(16)查询所有员工姓名的前3个字符。
select substr(e.ename,1,3) from emp e; --(17)查询所有员工的姓名,如果包含字母“s”,则用“S”替换。
select replace(lower(e.ename),'s','S') from emp e; --(18)查询员工的姓名和入职日期,并按入职日期从先到后进行排列。
select e.ename,e.hiredate from emp e order by e.hiredate --(19)显示所有的姓名、工种、工资和奖金,按工种降序排列,若工种相同则按工资升序排列。
select e.ename,e.job,e.sal,e.comm from emp e order by e.job desc,e.sal asc --(20)显示所有员工的姓名、入职的年份和月份,若入职日期所在的月份排序,若月份相同则按入职的年份排序。
select e.ename,extract(year from e.hiredate) y,extract(month from e.hiredate) m from emp e order by m,y --(21)查询在2月份入职的所有员工信息。
select * from emp e where extract(month from e.hiredate)=2 --(22)查询所有员工入职以来的工作期限,用“**年**月**日”的形式表示。 select extract(year from e.hiredate)||'年'||extract(month from e.hiredate)||'月'||extract(day from e.hiredate)||'日' from emp e --(23)查询至少有一个员工的部门信息。
select distinct d.* from dept d join emp e on d.deptno=e.deptno --(24)查询工资比SMITH员工工资高的所有员工信息。
select * from emp e where e.sal>(select e.sal from emp e where e.ename='SMITH') --(25)查询所有员工的姓名及其直接上级的姓名。
select m.ename,e.ename from emp e join emp m on e.empno=m.mgr; --(26)查询入职日期早于其直接上级领导的所有员工信息。
select m.* from emp e join emp m on e.empno=m.mgr and e.hiredate<m.hiredate; --(27)查询所有部门及其员工信息,包括那些没有员工的部门。
select * from emp e right join dept d on e.deptno=d.deptno --(28)查询所有员工及其部门信息,包括那些还不属于任何部门的员工。
select * from emp e left join dept d on e.deptno=d.deptno --(29)查询所有工种为CLERK的员工的姓名及其部门名称。
select e.ename,d.dname from emp e natural join dept d where e.job='CLERK' --(30)查询最低工资大于2500的各种工作。
select distinct e.job from emp e where e.sal > 2500 --(31)查询最低工资低于2000的部门及其员工信息。
select *
from emp
where deptno in
(select deptno
from (select min(sal) min_sal, deptno from emp group by deptno)
where min_sal < ''); --(32)查询在SALES部门工作的员工的姓名信息。
select e.ename from emp e natural join dept d where d.dname='SALES'; --(33)查询工资高于公司平均工资的所有员工信息。
select * from emp e where e.sal > (select avg(e.sal) from emp e) --(34)查询与SMITH员工从事相同工作的所有员工信息。
select * from emp e where e.job=(select e.job from emp e where e.ename='SMITH') --(35)列出工资等于30号部门中某个员工工资的所有员工的姓名和工资。
select e.ename,e.sal from emp e where e.sal = any(select e.sal from emp e where e.deptno=30) --(36)查询工资高于30号部门中工作的所有员工的工资的员工姓名和工资。 select e.ename,e.sal from emp e where e.sal > all(select e.sal from emp e where e.deptno=30) --(37)查询每个部门中的员工数量、平均工资和平均工作年限。
select count(1),avg(e.sal),avg(months_between(sysdate,e.hiredate)/12) from emp e group by e.deptno --(38)查询从事同一种工作但不属于同一部门的员工信息。
select e.* from emp e join emp m on e.job=m.job and e.deptno!=m.deptno --(39)查询各个部门的详细信息以及部门人数、部门平均工资。
select *
from (select d.deptno deptno, count(e.deptno), avg(e.sal)
from emp e
right join dept d
on e.deptno = d.deptno
group by d.deptno) m natural
join dept d --(40)查询各种工作的最低工资。
select e.job, min(e.sal) from emp e group by e.job --(41)查询各个部门中的不同工种的最高工资。
select e.deptno,e.job,max(e.sal) from emp e group by e.deptno,e.job --(42)查询10号部门员工以及领导的信息。
select * from emp e where e.deptno=10; --(43)查询各个部门的人数及平均工资。
select e.deptno, count(1) , avg(e.sal) from emp e group by e.deptno --(44)查询工资为某个部门平均工资的员工信息。
select * from emp e where e.sal in (select avg(e.sal) from emp e group by e.deptno) --(45)查询工资高于本部门平均工资的员工的信息。
select e.*
from emp e natural
join (select e.deptno d, avg(e.sal) a from emp e group by e.deptno) m
where e.sal > m.a
and e.deptno = m.d --(46)查询工资高于本部门平均工资的员工的信息及其部门的平均工资。
select e.*,m.a
from emp e natural
join (select e.deptno d, avg(e.sal) a from emp e group by e.deptno) m
where e.sal > m.a
and e.deptno = m.d --(47)查询工资高于20号部门某个员工工资的员工的信息。
select *
from emp e
where e.sal > any (select e.sal from emp e where e.deptno = 20) --(48)统计各个工种的人数与平均工资。
select e.job,count(e.empno) ,nvl(avg(e.sal),0) from emp e group by e.job --(49)统计每个部门中各个工种的人数与平均工资。
select e.deptno, e.job, count(e.empno), nvl(avg(e.sal), 0)
from emp e
group by e.job, e.deptno
order by e.deptno --(50)查询工资、奖金与10 号部门某个员工工资、奖金都相同的员工的信息。
select *
from emp e
where e.sal in (select e.sal from emp e where e.deptno = 10)
and e.comm in (select e.comm from emp e where e.deptno = 10) select emp.*
from emp
join (select sal, comm from emp where deptno = 10) t
on emp.sal = t.sal
and nvl(emp.comm, 0) = nvl(t.comm, 0)
and emp.deptno != 10; --(51)查询部门人数大于5的部门的员工的信息。
select e.*
from emp e natural
join (select e.deptno d, count(1) a from emp e group by e.deptno) m
where m.a > 5 and e.deptno=m.d --(52)查询所有员工工资都大于1000的部门的信息。
select *
from dept d
where d.deptno not in (select e.deptno from emp e where e.sal < 1000) --(53)查询所有员工工资都大于1000的部门的信息及其员工信息。 select distinct *
from emp e
join (select *
from dept d
where d.deptno not in
(select e.deptno from emp e where e.sal < 1000)) m
on e.deptno = m.deptno --(54)查询所有员工工资都在900~3000之间的部门的信息。
--一
select *
from dept d
where d.deptno in
(select distinct d.deptno
from dept d
right join emp e
on e.deptno = d.deptno
and d.deptno not in
(select e.deptno
from emp e
where e.sal not between 900 and 3000))
--二
select *
from dept
where deptno in (select distinct deptno
from emp
where deptno not in
(select distinct deptno
from emp
where sal not between 900 and 3000)); --(55)查询所有工资都在900~3000之间的员工所在部门的员工信息。
select *
from emp e
where e.deptno not in
(select e.deptno from emp e where e.sal not between 900 and 3000) --(56)查询每个员工的领导所在部门的信息。
select *
from dept d
where d.deptno in
(select m.deptno from emp e right join emp m on e.mgr = m.empno) --(57)查询人数最多的部门信息。
select *
from dept d
join (select e.deptno d, count(1) a from emp e group by e.deptno) m
on d.deptno = m.d
and m.a = (select max(count(1)) a from emp e group by e.deptno) --(58)查询30号部门中工资排序前3名的员工信息。
select *
from (select * from emp e where e.deptno = 30 order by e.sal desc) m
where rownum <= 3 --(59)查询所有员工中工资排在5~10名之间的员工信息。
select *
from (select m.*, rownum r
from (select * from emp e order by e.sal desc) m
where rownum <= 10) mm
where mm.r > 5 --(60)向emp表中插入一条记录,员工号为1357,员工名字为oracle,工资为2050元,部门号为20,入职日期为2002年5月10日。
insert into emp (empno,ename,hiredate,sal,deptno) values(1357,'oracle','5/10月/2002',2050,20); select * from emp --(61)向emp表中插入一条记录,员工名字为FAN,员工号为8000,其他信息与SMITH员工的信息相同。
insert into emp values(8000,'FAN',(select job,mgr,hiredate,sal,comm,deptno from emp where ename='SMITH')) --(62)将各部门员工的工资修改为该员工所在部门平均工资加1000。
update emp t1
set sal =
(select new_sal
from (select avg(sal) + 1000 new_sal, deptno
from emp
group by deptno) t2 wher e t1.deptno = t2.deptno);

oracle语法练习汇总的更多相关文章

  1. Oracle 数据库知识汇总篇

    Oracle 数据库知识汇总篇(更新中..) 1.安装部署篇 2.管理维护篇 3.数据迁移篇 4.故障处理篇 5.性能调优篇 6.SQL PL/SQL篇 7.考试认证篇 8.原理体系篇 9.架构设计篇 ...

  2. Oracle横向纵向汇总

    Oracle横向纵向汇总 有一张表test 如下, (NO 学生编号 ,cj 成绩) NO name KM CJ 001 张三 语文 80  001 张三 数学 86  001 张三 英语 75  0 ...

  3. shell脚本语法基础汇总

    shell脚本语法基础汇总 将命令的输出读入一个变量中,可以将它放入双引号中,即可保留空格和换行符(\n) out=$(cat text.txt) 输出1 2 3 out="$(cat te ...

  4. ORACLE常用函数汇总(持续更新中....)

    在使用ORACLE过程中,把一些常用的函数的相关用法,注意事项进行简单的汇总,便于自己查询参考. DBMS_RANDOM包 dbms_random是一个可以生成随机数值或者字符串的程序包.这个包有in ...

  5. Oracle基础知识汇总一

    Oracle基础知识 以下内容为本人的学习笔记,如需要转载,请声明原文链接   https://www.cnblogs.com/lyh1024/p/16720759.html oracle工具: SQ ...

  6. Oracle常用函数汇总

    在Oracle OCP考试中,相当一部分知识点涉及到对于Oracle常见函数的考查.尽管Oracle官方文档SQL Language Reference中Functions一章内列举了所有Oracle ...

  7. Oracle 语法

    1.行转列函数 11gR2以前: WM_CONCAT函数, 使用方式形如: SELECT SUS_SNO,WM_CONCAT(SRC_FILENAME) AS AAA FROM AML_SUS_TRD ...

  8. SQLServer、MySQL、Oracle语法差异小集锦

    一.差异集锦 在建表的时候,只有自增的语法不同. 下面给出3种数据库通用的建表与初始化测试语句: CREATE TABLE Country( Id int PRIMARY KEY, Name ) ); ...

  9. Oracle存储过程知识汇总

    基本语法篇: CREATE OR REPLACE PROCEDURE 存储过程名 //CREATE OR REPLACE PROCEDURE 是一个SQL语句通知Oracle数据库去创建一个叫做ske ...

随机推荐

  1. 深度学习—BN的理解(一)

    0.问题 机器学习领域有个很重要的假设:IID独立同分布假设,就是假设训练数据和测试数据是满足相同分布的,这是通过训练数据获得的模型能够在测试集获得好的效果的一个基本保障.那BatchNorm的作用是 ...

  2. 团队小组NABCD(通用作业和个人作业)特点

    NABCD框架(通用作业和个人作业): N(need,需求): 你的创意解决了用户的什么需求? 使用户能够很好的区分作业情况,将班里所有同学的作业和自己私人的作业分开,通用作业指在一个班一同上课的公共 ...

  3. Android中播放DSD音乐

    Github上有个简单的Alsa DSD测试程序,可以播放DSD,地址位于:https://github.com/zonque/alsa-dsd-player 细看其代码,发现有ALSA_FORMAT ...

  4. Amazon EMR(Elastic MapReduce):亚马逊Hadoop托管服务运行架构&Hadoop云服务之战:微软vs.亚马逊

    http://s3tools.org/s3cmd Amazon Elastic MapReduce (Amazon EMR)简介 Amazon Elastic MapReduce (Amazon EM ...

  5. 02-THREE.JS 辅助线使用

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  6. 深入浅出Mybatis系列(九)---强大的动态SQL(转载)

    原文出处:http://www.cnblogs.com/dongying/p/4092662.html 上篇文章<深入浅出Mybatis系列(八)---mapper映射文件配置之select.r ...

  7. tensorflow中创建多个计算图(Graph)

    tf程序中,系统会自动创建并维护一个默认的计算图,计算图可以理解为神经网络(Neural Network)结构的程序化描述.如果不显式指定所归属的计算图,则所有的tensor和Operation都是在 ...

  8. CF 36E Two Paths——欧拉路

    题目:http://codeforces.com/contest/36/problem/E 找出两条欧拉路覆盖无向图. 套上欧拉路模板.用过的边要记录. 注意 一个连通块.4个奇度数点 的情况是在两个 ...

  9. immutable学习

    React 做性能优化时有一个避免重复渲染的大招,就是使用 shouldComponentUpdate(),但它默认返回 true,即始终会执行 render() 方法,然后做 Virtual DOM ...

  10. Azure VMSS ---- PowerShell创建自定义镜像的VMSS集群

    前面一篇文章介绍了如何用PowerShell创建标准镜像的VMSS集群.http://www.cnblogs.com/hengwei/p/7391178.html 本文将介绍,如何用PowerShel ...