《第11章 SQL練習答案》由會員分享,可在線閱讀,更多相關《第11章 SQL練習答案(10頁珍藏版)》請在裝配圖網上搜索。
1、【精品文檔】如有侵權,請聯系網站刪除,僅供學習與交流第11章 SQL練習答案.精品文檔.1實訓題根據人力資源管理系統(tǒng)數據庫中數據信息,完成下列操作。(1) 查詢100號部門的所有員工信息。Selsect * from employees where department_id = 100(2) 查詢所有職位編號為“SA_MAN”的員工的員工號、員工名和部門號。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”的員工的信息。Select * from employees where department_id=40 and job_id= AD_ASST OR department_id=20 and job_id= SA_REP;(5) 查詢所有職位名稱不是“Stock Manager”和“Purchasing Manager”,且工資
3、大于或等于2000的員工的詳細信息。Select * from employees where job_id not in( Stock Manager, Purchasing Manager) and salary=2000(6) 查詢有獎金的員工的不同職位編號和名稱。 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元的員工信息。Select * from employees
4、 where salary*commission_pct100 or commission is NULL(8) 查詢員工名(first_name)中不包含字母“S”的員工。Select first_name from employees where first_name not like %S%(9) 查詢員工的姓名和入職日期,并按入職日期從先到后進行排序。Select first_name,last_name,hire_date from employees order by hire_date;(10) 顯示所有員工的姓名、職位、工資和獎金,按職位降序排序,若職位相同則按工資升序排序。S
5、elect first_name,last_name,job_id,salary ,salary*commission_pet from employees order by job_id desc ,salary asc;(11) 查詢所有員工的姓名及其直接上級的姓名。Select a.first_name,b.first_name from employees a join employees b on b.employee_id = a.manage_id (12) 查詢入職日期早于其直接上級領導的所有員工信息。 select * from employees a where hire_
6、date(select salary from employees where employee_id = 100);(19) 查詢工資高于公司平均工資的所有員工信息。Select * from employees where salary(select avg(salary) from employees)(20) 查詢各個部門中不同職位的最高工資。Select job_id,max(salary) from employees group by job_id(21) 查詢各個部門的人數及平均工資 Select department_id,count(*),avg(salary ) from
7、 employees group by department_id; (22) 統(tǒng)計各個職位的員工人數與平均工資。Select job_id ,count(employee_id),avg(salary) from employees group by job_id;(23) 統(tǒng)計每個部門中各職位的人數與平均工資。Select department_id,job_id,count(*),avg(salary) from employees group by department_id,job_id;(24) 查詢最低工資大于5000元的各種工作。Select job_id,job_title
8、from jobs where job_id in(Select job_id from employees group by job_id having min(salary)5000);(25) 查詢平均工資低于6000元的部門及其員工信息。 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(s
9、alary)(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 depar
10、tment_id)(31) 查詢工資高于本部門平均工資的員工的信息。Select * from employees e1 where salary(select avg(salary) from employees e2 where e2.department_id=e1.department_id )(32) 查詢工資高于本部門平均工資的員工的信息及其部門的平均工資。Select e.*,avgsalFrom employees e join (select department_id,avg(salary) avgsal from employees group by department
11、_id) dOn e.department_id=d.department_id And e.salaryd.avgsal(33) 查詢工資高于50號部門某個員工工資的員工的信息。Select *from employees where salaryany(select salary from employees where department_id=50):(34) 查詢工資、獎金與10號部門某員工工資、獎金都相同的員工的信息。Select * from employees where (salary,nvl(commission_pct) ) in(Select salary,nvl(c
12、ommission_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 e
13、mployees 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)=all(select count(*) from emp
14、loyees 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) 查詢所有員工中工資排序在510名之間的員工信息。Select * from Select rownum rn,employee_id,salary from (Select employee_id,salary from employees where salary i
15、s not null order by salary desc) e1 )e2Where rn between 5 and 10(41) 向employees表中插入一條記錄,員工號為1000元,入職日期為2002年5月10日,email為example,其他信息與員工號為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月份入職的所有員工信息。