您的位置:首页 > 数据库 > Oracle

Oracle数据库上机练习1

2019-06-16 07:39 3919 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NSJim/article/details/89600349

Oracle上机练习题(一)

试卷总分:100

答题时间:120分钟

 

一、Oracle上机练习题

 

1.

查询100号部门的所有员工信息[2分]

SELECT * FROM employees WHERE department_id = 100

2.

查询所有岗位编号为“SA_MAN"的员工的员工号、员工名和部门号。[2分]

SELECT employee_id,first_name,last_name,department_id FROM employees WHERE job_id = 'SA_MAN'

3.

查询每个员工的员工号、工资、奖金以及工资与奖金的和。[2分]

SELECT employee_id,salary,commission_pct,salary*(1+nvl(commission_pct,0) FROM employees

4.

查询40号部门中职位编号为“ad_asst”和20号部门中职位编号为“sa_rep”的员工信息。[2分]

SELECT * FROM employees WHERE department_id=40 AND job_id='AD_ASST' OR department_id=20 AND job_id='SA_REP'

5.

查询职位名称不为“stockmanager”和“purchasing manager”且工资大于等于2000元的员工详细信息[2分]

SELECT * FROM employees WHERE job_id not in('stockmanager','purchasing') AND salary >= 2000

6.

查询有奖金的员工不同的职位编号和名称。[2分]

SELECT distinct job_id,job_title FROM jobs WHERE job_id in(SELECT job_id FROM employees WHERE job_id is not null

7.

查询没有奖金或奖金低于100元的员工信息。[2分]

SELECT * from employees WHERE salary*commission_pct<100 OR commission is NULL

8.

查询员工名(first_name)中不包含“s”的员工。[2分]

SELECT first_name FROM employees WHERE first_name LIKE '%S%'

9.

查询员工的姓名和入职日期,并按入职日期从先到后进行排序。[2分]

SELECT first_name,last_name,hire_date FROM employees ORDER BY hire_date

10.

显示所有员工的姓名、职位、工资和奖金,按职位降序排序,若职位相同则按工资升序排序。[2分]

SELECT first_name,last_name,job_id,salary,salary*commission_pet FROM employees ORDER BY job_id DESC,salary ASC

11.

查询所有员工的姓名及其直接上级的姓名。[2分]

SELECT a.first_name,b.first_name FROM employees a join employees b on b.employee_id = a.manage_id

12.

查询入职日期早于其直接上级领导的所有员工信息[2分]

SELECT * FROM employees a WHERE hire_date<(SELECT hire_date FROM employees b b.employees_id=a.manage_id)

13.

查询各个部门部门号,部门名称,部门所在地及部门的领导姓名。[2分]

SELECT d.department_id,d.department_name,d.location,e.first_name FROM departments d JOIN employees e on d.manager_id=e.employee_id

14.

查询所有部门及其员工信息,包括哪些没有员工的部门[2分]

SELECT department_name,first_name FROM departments d LEFT JOIN employees e on d.department_id=e.department_id

15.

查询所有员工及其部门信息,包括那些还不属于任何部门的员工。[2分]

SELECT e.first_name,d.department_name FROM employees LEFT JOIN departments on e.department_id=d.department_id

16.

查询所有员工的员工号,员工名,部门名称,职位名称,工资和奖金[2分]

SELECT e.employee_id,e.first_name,d.department_name,j.job_title,e.salary,e.salary*e.commission_pct FROM departments d JOIN employees e ON d.department_id=e.department_id JOIN jobs j on j.job_id=e.job_id

17.

查询至少有一个员工的部门信息[2分]

SELECT DISTINCT departments.* FROM departments d join employees e on e.employee_id is not NULL

18.

查询工资比100号员工工资高的所有员工信息[2分]

SELECT * FROM employees WHERE salary>(SELECT salary FROM employees where employee_id=100)

19.

查询工资高于公司平均工资的所有员工信息[2分]

SELECT * FROM employees WHERE salary>(SELECT avg(salary) FROM employees)

20.

查询各个部门中不同职位的最高工资[2分]

SELECT job_id,max(salary) FROM employees GROUP BY job_id

21.

查询各个部门的人数及平均工资[2分]

SELECT department_id,count(*),avg(salary) FROM employees GROUP BY department_id

22.

统计各个职位的员工数与平均工资[2分]

SELECT job_id,count(employee_id),avg(salary) FROM employees GROUP BY job_id

23.

统计每个部门中各职位的人数与平均工资[2分]

SELECT department_id,job_id,count(*),avg(salary) FROM employees GROUP BY department_id,job_id

24.

查询最低工资大于5000元的各种工种[2分]

SELECT job_,job_title FROM jobs WHERE job_id in(SELECT job_id FROM employees GROUP BY job_id having min(salary)>5000)

25.

查询平均工资低于6000元的部门及其员工信息[2分]

SELECT e.*,d.* FROM employees e JOIN departments d ON e.department_id=d.department_id AND department_id IN(SELECT department_id FROM employees GROUP BY employee_id having avg(salary)<6000)

26.

查询在“Sales”部门工作的员工姓名和部门号[2分]

select * from employee where department_id in(salary department_id from departments where department_name='Sales'

27.

查询与140号员工从事相同工作的所有员工信息[2分]

select * from employees where job_id in(select job_id from employees where employee_id=140)

28.

查询员工工资高于30号部门中所有员工的工资的员工姓名和工资以及部门号[2分]

select first_name,last_name,salary from employees where salary>(select max(salary) from employees group by department_id having department_id=30)

29.

查询每个部门中部门号,员工数量,平均工资和平均工作年限。[2分]

select count(*),avg(salary),avg(round((sysdate-hire_date)/365)) from employees group by department_id

30.

查询工资为某个部门平均工资的员工的信息[2分]

select * from employees where salary in(select avg(salary) from employees group by department_id)

31.

查询工资高于本部门平均工资的员工信息 [2分]

select * from employees e1 where salary>(salary avg(salary) from employees e2 where e2.department_id=e1.department_id)

32.

查询工资高于本部门平均工资的员工信息及其部门的平均工资。[2分]

select e.*,avgsal from employees e join (select department_id,avg(salary) avgsal from employees group by department_id) d on e.department_id=d.department_id and e.salary>d.avgsal

33.

查询工资高于50号部门某个员工工资的员工信息[2分]

select * from employees where salary>any(select salary from employees where department_id=50)

34.

查询工资,奖金与10号部门某员工工资,奖金都相同的员工信息[2分]

select * from employees where (salary,nvl(commission_pct)) in(select salary,nvl(commission_pct) from employees where department_id=10

35.

查询部门人数大于10的部门员工信息[2分]

select * from employees where department_id in(select department_id from employees group by department_id having count(*)>10)

36.

查询所有员工工资都大于10000的部门信息[2分]

select * from department where department_id in(select department_id from employees group by department_id having min(salary)>10000)

37.

查询所有员工工资都大于5000元的部门的信息及其员工信息[2分]

select * from departments d,employees e where d.department_id=e.department_id group by department_id having min(salary)>5000

38.

查询所有员工工资都在4000-8000元之间的部门的信息[2分]

select * from departments where department_id in(select department_id from employees group by department_id having min(slary)>=4000 and max(salary)<=8000)

39.

查询人数最多的部门信息。[2分]

select * from department_id where department_id in(select department_id from employees group by department_id having count(*)>=all(select count(*) from employees group by department_id))

40.

查询30号部门中工资排序前3名的员工信息。[2分]

select * from employee where department_id=30 and salary is not null and rownum<=3 order by salary desc

41.

查询所有员工中工资排序在5-10名之间的员工信息。[2分]

select * from (select rownum rn,employee_id,salary from(select employee_id,salary from employees where salary is not null order by salary desc) e1)e2 where rn between 5 and 10

42.

向employees表中插入一条记录,员工号为1000,入职日期为2002年5月10日,emial为example@neusoft.edu.cn,其他信息与员工号为150的员工相同。[2分]

insert into employees select 1000,first_name,last_name,'example@nuesoft.edu.cn',phone_number,to_date('10-05-2002','dd-mm-yyyy'),job_id,salary,commission_pct,manager_id,department_id from employees where employee_id=150

43.

将各部门员工的工资修改为该员工所在部门平均工资加1000元[2分]

update employee b

set sal=(select sal from (select deptno,avg(sal)+1000 sal from employee group by deptno) a where a.deptno=b.deptno)

44.

查询各月倒数第二天入职的员工信息[2分]

select * from employees where hire_date=last_day(hire_date)-1

45.

查询工龄大于或等于10年的员工信息。[2分]

select * from employees where (sysdate-hire_date)/365>=10

46.

查询员工信息,要求以首字母大写的方式显示所有员工姓和员工名。[2分]

select employee_id,initcap(first_name),initcap(last_name) from employees

47.

查询员工名(first_name)正好为6个字符的员工的信息[2分]

select * from employees where length(first_name)=6

48.

查询员工名(first_name)的第二个字母为“M”的员工信息[2分]

select * from employees where first_name like '_M%'

49.

查询所有员工名(first_name),如果包含字母”s”,则用“S”替换[2分]

select replace(first_name,'s','S') from employees

50.

查询在2月份入职的所有员工信息[2分]

select * from employees where extract(month from hire_date)=2

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: