第11章 SQL练习答案(2)

2019-08-29 20:19

Select e.first_name||e.last_name from employees e join departments d on e.department_id=d.department_id where d.department_name = ‘Sales’;

Select * from employee where department_id in(select department_d from departments where department_name=’Sales’)

(27) 查询与140号员工从事相同工作的所有员工信息。 Select * from employees where job_id in (select job_id from employees where employee_id = 140);

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

Select first_name,last_name,salary from employees where salary>(select max(salary) from employees deparment_id=30); (29) 查询每个部门中的员工数量、平均工资和平均工作年限。 Select count(*),avg(salary),avg(round((sysdate-hire_date)/365)) from employees group by department_id

(30) 查询工资为某个部门平均工资的员工的信息。 Select * from employees where salsry in(select avg(Salary) from employees group by department_id)

(31) 查询工资高于本部门平均工资的员工的信息。 Select * from employees e1 where salary>(select avg(salary) from

employees e2 where e2.department_id=e1.department_id ) (32) 查询工资高于本部门平均工资的员工的信息及其部门的平均工资。 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号部门某个员工工资的员工的信息。 Select *from employees where salary>any(select salary from employees where department_id=50):

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

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

(35) 查询部门人数大于10的部门的员工信息。

Select * from employees where department_id in(select department_id from employees group by department_id having count(*)>10); 查询所有员工工资都大于10000元的部门的信息

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

(36) 查询所有员工工资都大于5000元的部门的信息及其员工信息。

(37) 查询所有员工工资都在4000元~8000元之间的部门的信息。

Select * from departments where department_id in(

Select department_id from employees group by department_id having min(salary)>=4000 and max(salary)<=8000)

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

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 ) )

(39) 查询30号部门中工资排序前3名的员工信息。 Select * from employee where department_id=30 and salary is not null and rownum<=3 order by salary desc

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

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

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

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

(43) 查询各月倒数第2天入职的员工信息。 (44) 查询工龄大于或等于10年的员工信息。

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

(46) 查询员工名(first_name)正好为6个字符的员工的信息。 (47) 查询员工名(first_name)的第2个字母为“M”的员工

信息。

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

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


第11章 SQL练习答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:南京工业大学化学化工学院师资队伍

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: