根据Oracle数据库scott模式下的scott.emp表和dept表,完成下列操作.

2023-05-16

题目要求:根据Oracle数据库scott模式下的emp表和dept表,完成下列操作。


将scott用户解锁:

alter user scott account unlock

scott的初始密码是tiger,解锁后要重新设置密码

之后直接连接就可以了,

conn scott / tiger


emp 表:

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM 
---------- ---------- --------- ---------- -------------- ---------- ---------- 
    DEPTNO                                                                      
----------                                                                      
      7369 SMITH      CLERK           7902 17-12月-80            800            
        20                                                                      
                                                                                
      7499 ALLEN      SALESMAN        7698 20-2月 -81           1600        300 
        30                                                                      
                                                                                
      7521 WARD       SALESMAN        7698 22-2月 -81           1250        500 
        30                                                                      
                                                                                
      7566 JONES      MANAGER         7839 02-4月 -81           2975            
        20                                                                      
                                                                                
      7654 MARTIN     SALESMAN        7698 28-9月 -81           1250       1400 
        30                                                                      
                                                                                
      7698 BLAKE      MANAGER         7839 01-5月 -81           2850            
        30                                                                      
                                                                                
      7782 CLARK      MANAGER         7839 09-6月 -81           2450            
        10                                                                      
                                                                                
      7788 SCOTT      ANALYST         7566 19-4月 -87           3000            
        20                                                                      
                                                                                
      7839 KING       PRESIDENT            17-11月-81           5000            
        10                                                                      
                                                                                
      7844 TURNER     SALESMAN        7698 08-9月 -81           1500          0 
        30                                                                      
                                                                                
      7876 ADAMS      CLERK           7788 23-5月 -87           1100            
        20                                                                      
                                                                                
      7900 JAMES      CLERK           7698 03-12月-81            950            
        30                                                                      
                                                                                
      7902 FORD       ANALYST         7566 03-12月-81           3000            
        20                                                                      
                                                                                
      7934 MILLER     CLERK           7782 23-1月 -82           1300            
        10                                                                    

dept表:

 DEPTNO DNAME          LOC                                                   
---------- -------------- -------------                                         
        10 ACCOUNTING     NEW YORK                                              
        20 RESEARCH       DALLAS                                                
        30 SALES          CHICAGO                                               
        40 OPERATIONS     BOSTON      

题目要求:根据Oracle数据库scott模式下的emp表和dept表,完成下列操作。

(1)      查询20号部门的所有员工信息。

select * from emp where deptno = 20;

(2)      查询所有工种为CLERK的员工的工号、员工名和部门名。

select empno,ename,deptno from emp where job like 'CLERK';

(3)      查询奖金(COMM)高于工资(SAL)的员工信息。

select * from emp where comm > sal;

(4)      查询奖金高于工资的20%的员工信息。

select * from emp where comm > (sal*0.2);

(5)      查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息。

select * from emp

where (deptno = 10 and job like 'MANAGER') or (deptno = 20and job like 'CLERK');

(6)      查询所有工种不是MANAGER和CLERK,且工资大于或等于2000的员工的详细信息。

select * from emp where job not in ('MANAGER','CLERK') andsal >= 2000 ;

(7)      查询有奖金的员工的不同工种。

select distinct job from emp where comm is not null;

(8)      查询所有员工工资和奖金的和。

select ename,(sal+nvl(comm,0)) salcomm from emp;

(9)      查询没有奖金或奖金低于100的员工信息。

select * from emp where (comm is null or comm < 100) ;

(10)  查询各月倒数第2天入职的员工信息。

select * from emp where hiredate in (select(last_day(hiredate)-1) from emp);

(11)  查询员工工龄大于或等于10年的员工信息。

select * from emp where (sysdate - hiredate)/365 >= 10 ;

(12)  查询员工信息,要求以首字母大写的方式显示所有员工的姓名。

select upper(substr(ename,1,1)) ||lower(substr(ename,2,length(ename)-1)) from emp;

(13)  查询员工名正好为6个字符的员工的信息。

select * from emp where lengthename= 6 ;

(14)  查询员工名字中不包含字母“S”员工。

select * from emp where ename not in (select ename from empwhere ename like '%S%') ;

select * from emp where ename not like ‘%S%’;

(15)  查询员工姓名的第2个字母为“M”的员工信息。

select * from emp where ename like '_M%';

(16)  查询所有员工姓名的前3个字符。

select substr(ename,1,3) from emp ;

(17)  查询所有员工的姓名,如果包含字母“s”,则用“S”替换。

select replace(ename,'s','S') from emp ;

(18)  查询员工的姓名和入职日期,并按入职日期从先到后进行排列。

select ename,hiredate from emp order by hiredate asc ;

(19)  显示所有的姓名、工种、工资和奖金,按工种降序排列,若工种相同则按工资升序排列。

select ename,job,sal,comm from emp order by job desc,sal asc;

(20)  显示所有员工的姓名、入职的年份和月份,若入职日期所在的月份排序,若月份相同则按入职的年份排序。

select ename,to_char(hiredate,'yyyy')||'-'||to_char(hiredate,'mm')from emp order by to_char(hiredate,'mm'),to_char(hiredate,'yyyy');

(21)  查询在2月份入职的所有员工信息。

select * from emp where to_char(hiredate,'mm') = 2 ;

(22)  查询所有员工入职以来的工作期限,用“**年**月**日”的形式表示。

select ename,floor((sysdate-hiredate)/365)||''||floor(mod((sysdate-hiredate),365)/30)||''||cell(mod(mod((sysdate-hiredate),365),30))||'' fromemp ;

(23)  *查询至少有一个员工的部门信息。

select * from dept where deptno in (select distinct deptnofrom emp where mgr is not null) ;

(24)  *查询工资比SMITH员工工资高的所有员工信息。

select * from emp where sal > (select sal from emp whereename like 'SMITH') ;

(25)  查询所有员工的姓名及其直接上级的姓名。

select staname,ename supname from (select ename staname,mgrfrom emp) t join emp on t.mgr=emp.empno ;

(26)  查询入职日期早于其直接上级领导的所有员工信息。

select * from emp where empno in (select staempno from(select empno staempno,hiredate stahiredate,mgr from emp) t join emp ont.mgr=emp.empno and stahiredate < hiredate) ;

(27)  *查询所有部门及其员工信息,包括那些没有员工的部门。

select * from dept left join emp on emp.deptno=dept.deptnoorder by dept.deptno ;

(28)  *查询所有员工及其部门信息,包括那些还不属于任何部门的员工。

 

(29)  *查询所有工种为CLERK的员工的姓名及其部门名称。

select ename,dname from emp join dept on job like 'CLERK' andemp.deptno=dept.deptno ;

(30)  查询最低工资大于2500的各种工作。

select job from (select min(sal) min_sal,job from emp groupby job) where min_sal > 2500 ;

(31)  *查询最低工资低于2000的部门及其员工信息。

select * from emp where deptno in (select deptno from (selectmin(sal) min_sal,deptno from emp group by deptno) where min_sal < '2000') ;

(32)  查询在SALES部门工作的员工的姓名信息。

select ename from emp where deptno = (select deptno from deptwhere dname like 'SALES');

(33)  *查询工资高于公司平均工资的所有员工信息。

select * from emp where sal > (select avg(sal) from emp) ;

(34)  *查询与SMITH员工从事相同工作的所有员工信息。

select * from emp where job in (select job from emp whereename like 'SMITH') and ename not like 'SMITH' ;

(35)  *列出工资等于30号部门中某个员工工资的所有员工的姓名和工资。

select ename,sal from emp where sal =any (select sal from empwhere deptno = 30) ;

(36)  *查询工资高于30号部门中工作的所有员工的工资的员工姓名和工资。

select ename,sal from emp where sal >all (select sal fromemp where deptno = 30) ;

(37)  查询每个部门中的员工数量、平均工资和平均工作年限。

select dname,count,avg_sal,avg_date from dept join (selectcount(*) count,avg(sal) avg_sal,avg((sysdate-hiredate)/365) avg_date,deptnofrom emp group by deptno) t on dept.deptno = t.deptno ;

(38)  *查询从事同一种工作但不属于同一部门的员工信息。

select distinct t1.empno,t1.ename,t1.deptno from emp t1 joinemp t2 on t1.job like t2.job and t1.deptno <> t2.deptno ;

(39)  *查询各个部门的详细信息以及部门人数、部门平均工资。

Select dept.*,person_num,avg_sal from dept,(select count(*)person_num,avg(sal) avg_sal,deptno from emp group by deptno) t wheredept.deptno = t.deptno ;

(40)  *查询各种工作的最低工资。

select job,min(sal) from emp group by job ;

(41)  查询各个部门中的不同工种的最高工资。

select max(sal),job,deptno from emp group by deptno,job orderby deptno,job

(42)  查询10号部门员工以及领导的信息。

select * from emp where empno in (select mgr from emp wheredeptno=10) or deptno = 10

(43)  查询各个部门的人数及平均工资。

select deptno,count(*),avg(sal) from emp group by deptno

(44)  *查询工资为某个部门平均工资的员工信息。

select * from emp where sal in (select avg(sal) avg_sal fromemp group by deptno) ;

(45)  *查询工资高于本部门平均工资的员工的信息。

select emp.* from emp join (select deptno,avg(sal) avg_salfrom emp group by deptno) t on emp.deptno=t.deptno and sal>avg_sal ;

(46)  查询工资高于本部门平均工资的员工的信息及其部门的平均工资。

select emp.*,avg_sal from emp join (select deptno,avg(sal)avg_sal from emp group by deptno) t on emp.deptno=t.deptno and sal>avg_sal ;

(47)  查询工资高于20号部门某个员工工资的员工的信息。

select * from emp where sal >any(select sal from emp wheredeptno=20);

(48)  *统计各个工种的人数与平均工资。

select job,count(*),avg(sal) from emp group by job ;

(49)  *统计每个部门中各个工种的人数与平均工资。

select deptno,job,count(*),avg(sal) from emp group bydeptno,job order by deptno,job;

(50)  查询工资、奖金与10 号部门某个员工工资、奖金都相同的员工的信息。

select emp.* from emp join (select sal,comm from emp wheredeptno = 10) t on emp.sal=t.sal and nvl(emp.comm,0)=nvl(t.comm,0) andemp.deptno != 10;

(51)  *查询部门人数大于5的部门的员工的信息。

select * from emp where deptno in (select deptno from empgroup by deptno having count(*)>5);

(52)  *查询所有员工工资都大于1000的部门的信息。

select * from dept where deptno in (select distinct deptnofrom emp where deptno not in (select distinct deptno from emp where sal <1000)) ;

(53)  *查询所有员工工资都大于1000的部门的信息及其员工信息。

select * from emp join dept on dept.deptno in (selectdistinct deptno from emp where deptno not in (select distinct deptno from empwhere sal < 1000)) and dept.deptno=emp.deptno;

(54)  *查询所有员工工资都在900~3000之间的部门的信息。

select * from dept where deptno in (select distinct deptnofrom emp where deptno not in (select distinct deptno from emp where sal notbetween 900 and 3000)) ;

(55)  查询所有工资都在900~3000之间的员工所在部门的员工信息。

select * from emp where deptno in (select distinct deptnofrom emp where deptno not in (select distinct deptno from emp where sal notbetween 900 and 3000)) ;

(56)  查询每个员工的领导所在部门的信息。

select * from (select e1.empno,e1.ename,e1.mgr mno,e2.enamemname,e2.deptno from emp e1 join emp e2 on e1.mgr=e2.empno) t join dept ont.deptno=dept.deptno ;

(57)  *查询人数最多的部门信息。

select * from dept where deptno in (select deptno from(select count(*) count,deptno from emp group by deptno) where count in (selectmax(count) from (select count(*) count,deptno from emp group by deptno)));

(58)  *查询30号部门中工资排序前3名的员工信息。

select * from emp where empno in (select empno from (selectempno,sal from emp where deptno=30 order by sal desc) where rownum < 4) ;

(59)  查询所有员工中工资排在5~10名之间的员工信息。

select * from emp where empno in (select empno from (selectempno,rownum num from (select empno,sal from emp order by sal desc)) where numbetween 5 and 10 ) ;

 

select empno from (select empno,sal from emp order by saldesc) where rownum <= 10 minus select empno from (select empno,sal from emporder by sal desc) where rownum < 5 ;

(60)  查询SMITH员工及所有其直接、间接下属员工的信息。

 

(61)  查询SOCTT员工及其直接、间接上级员工的信息。

 

(62)  以树状结构查询所有员工与领导之间的层次关系。

 

(63)  向emp表中插入一条记录,员工号为1357,员工名字为oracle,工资为2050元,部门号为20,入职日期为2002年5月10日。

insertinto emp(empno,ename,sal,deptno,hiredate) values(1357,'oracle',2050,20,to_date('2002510','yyyy""mm""dd""'));

(64)  向emp表中插入一条记录,员工名字为FAN,员工号为8000,其他信息与SMITH员工的信息相同。

 

(65)  将各部门员工的工资修改为该员工所在部门平均工资加1000。

update emp t1 set sal = (select new_sal from (selectavg(sal)+1000 new_sal,deptno from emp group by deptno) t2 wher e t1.deptno =t2.deptno ) ;

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

根据Oracle数据库scott模式下的scott.emp表和dept表,完成下列操作. 的相关文章

  • Windows 下源码编译 eos 人脸模型拟合库过程遇到的坑坑坑

    eos 是一个用现代 C 43 43 11 14 编写的轻量级三维形变人脸模型拟合库 xff0c 下面介绍下编译它的步骤和遇到的一些坑坑坑坑 xff01 博文的前半部分是用手动安装的 opencv 和 boost 构建和编译的 xff0c
  • Python DeprecationWarning the imp module is deprecated in favour of importlib

    报错 E PyCharm 2018 2 5 helpers pycharm docrunner py 1 DeprecationWarning the imp module is deprecated in favour of import
  • Unity3D 编辑器调试无响应问题

    问题描述 使用 VS 在 Unity 编辑器中调试代码 xff0c 点击 VS 的 附加到 Unity xff0c Unity 编辑器按下 Play 之后 xff0c 就会一直等待并且无其他响应 xff0c 只能结束 Unity 进程 原因
  • 获取 Windows 操作系统的系统、网络、硬件、软件等信息

    Github 源码 xff1a WindowsInfo Net可执行文件 xff1a WindowsInfo Net exe 获取的信息 能获得的信息如下 xff08 系统 硬件 网络信息已打码 xff09 系统信息 计算机名 xff1a
  • 一个基于 C# 的简单的线程安全日志模块

    一个基于 C 的简单的线程安全日志模块 xff0c 它使用生产者 消费者模式 xff0c 可以在 NET Framework 和 Net Core 中使用 Github 地址 xff1a LogConsumer 使用 将 LogConsum
  • Python爬虫深造篇(一)——多线程网页爬取

    一 前情提要 相信来看这篇深造爬虫文章的同学 xff0c 大部分已经对爬虫有不错的了解了 xff0c 也在之前已经写过不少爬虫了 xff0c 但我猜爬取的数据量都较小 xff0c 因此没有过多的关注爬虫的爬取效率 这里我想问问当我们要爬取的
  • c++多态和虚函数心得

    多态性 xff08 Polymorphism xff09 是指一个名字 xff0c 多种语义 xff1b 或界面相同 xff0c 多种实现 重载函数是多态性的一种简单形式 虚函数允许函数调用与函数体的联系在运行时才进行 xff0c 称为动态
  • IntelliJ IDEA 代码检查规范QAPlug

    转自 xff1a http blog csdn net jizi7618937 article details 51500725 Avoid Array Loops 数组之间的拷贝使用System arrayCopy更加高效 byte Re
  • linux系统中rpm与Yum软件仓库

    rpm的作用 xff1a 在没有rpm软件管理之前我们在安装 升级 卸载服务程序时要考虑到其他程序 库的依赖关系 xff0c 所以在进行安装 校验 卸载 升级等操作时的难度就非常之大 rpm机制则为就是为了解决这些问题而设计的 xff0c
  • Nokov使用说明(Windows系统)

    Nokov使用说明 第一步 镜头硬件调节1 连接镜头 xff0c 打开Seeker软件 xff08 以下简称软件 xff09 2 放置标定框3 调节镜头4 调焦1 xff09 调节后环 xff1a 光圈调到最大2 xff09 调节前环 xf
  • 计算机的存储器层次结构以及一二三级缓存的区别

    hibernate 一级缓存和二级缓存的区别 xff1a 主要的不同是它们的作用范围不同 一级缓存是session级别的 也就是只有在同一个session里缓存才起作用 xff0c 当这个session关闭后这个缓存就不存在了 而二级缓存是
  • Mac安装java反编译工具JD-GUI提示需要安装jdk1.8+解决方案

    一 下载 Java Decompiler JD Java Decompiler http java decompiler github io 二 当打开JD GUI软件时候 xff0c 会弹出以下错误 xff0c 见图示 xff1a 而自己
  • Docker命令详细说明

    Docker命令详细说明 docker help 查看docker帮助 使用方法 xff1a docker 命令选项 命令 参数 docker dameon help docker help v version config 61 dock
  • udev 规则文件介绍

    1 配置文件 udev的配置文件位于 etc udev 和 lib udev xff08 开头的是注释 xff09 udev 的主配置文件是 etc udev udev conf 它包含一套变量 xff0c 允许用户修改 udev 默认值
  • ATSAMV7Xult板卡调试Nuttx系统------NuttX模拟器SIM的的编译和调试

    NUTTX的模拟环境的编译和调试 xff1a 由于开发团队硬件资源紧张 xff0c 因此大家调试时可以使用模拟器来进行一些任务的开发和调试 参考 nuttx 7 17 configs sim readme txt介绍的操作方法 xff1a
  • C语言中,int、char、float、double各占多少字节

    https zhidao baidu com question 619738052995674092 html 只是数据类型不同而已 xff0c 在c语言中数据类型不同 xff0c 占的内存字节数不同 xff0c 所以表示数据大小不一样 i
  • 第一天做LeetCode 19.1.10

    为了备战蓝桥杯 xff0c 今天第一天做LeetCode xff0c 就做了一道题花了半个小时 xff0c 期间有各种错误 xff0c 深深的感受到自己连菜鸡都算不上 题目 xff1a 给定一个数组nums xff0c 与目标值target
  • 麻将通用胡牌算法详解(拆解法)

    1 背景 前几天刚好有项目需要胡牌算法 xff0c 查阅资料后 xff0c 大部分胡牌算法的博客都是只讲原理 xff0c 实现太过简单 xff0c 且没有给出测试用例 然后就有了下面的这个胡牌算法 xff0c 我将从算法原理和算法实现两部分
  • Java并发编程笔记之ThreadLocal内存泄漏探究

    转发 xff1a Java并发编程笔记之ThreadLocal内存泄漏探究 使用 ThreadLocal 不当可能会导致内存泄露 xff0c 是什么原因导致的内存泄漏呢 xff1f 我们首先看一个例子 xff0c 代码如下 xff1a Cr
  • 学长们的求职血泪史(C/C++/JAVA)

    2014届校招基本慢慢收尾 xff0c 现特将本人和小伙伴们的求职血泪史记录 xff0c 并且推荐一些书籍供学弟学妹们参考 xff0c 以壮我皇家理工之名 首先得感谢百度的师兄 xff0c 他教会了我很多东西 xff0c 致以很深的谢意 另

随机推荐