166.View the Exhibit and examine the structures of the EMPLOYEES and DEPARTMENTS tables.

166.View the Exhibit and examine the structures of the EMPLOYEES and DEPARTMENTS tables.
You want to update the EMPLOYEES table as follows:
-Update only those employees who work in Boston or Seattle (locations 2900 and 2700).
-Set department_id for these employees to the department_id corresponding to London (location_id 2100).
-Set the employees' salary in location_id 2100 to 1.1 times the average salary of their department.
-Set the employees' commission in location_id 2100 to 1.5 times the average commission of their
department.
You issue the following command:


SQL>UPDATE employees
SET department_id =
(SELECT department_id
FROM departments
WHERE location_id = 2100),
(salary, commission) =
(SELECT 1.1*AVG(salary), 1.5*AVG(commission)
FROM employees, departments
WHERE departments.location_id IN(2900,2700,2100))
WHERE department_id IN
(SELECT department_id
FROM departments
WHERE location_id = 2900
OR location_id = 2700)
What is the outcome?
A.It executes successfully and gives the correct result.
B.It executes successfully but does not give the correct result.
C.It generates an error because a subquery cannot have a join condition in an UPDATE statement.
D.It generates an error because multiple columns (SALARY, COMMISION) cannot be specified together in an UPDATE statement.
答案:B
解析:题目重第一条说是只更新工作在Boston or Seattle的人员,那么where条件是正确的,
第二条是更新department_id为工作在London的department_id,那么语句中update department_id也是正确的
第三条说是更新他们的salary为location_id=2100 的平均的1.1倍
第四条说是更新他们的commission为location_id=2100 的平均1.5被,这里对应的update中的WHERE departments.location_id IN(2900,2700,2100)
这个是错误的,应该为WHERE departments.location_id IN(2100)
上面这条语句看是否正确主要问题在department_id =
(SELECT department_id
FROM departments
WHERE location_id = 2100)这条语句,看是否返回单条记录,从题目中没有说明department_id和location_id是唯一值
那么如果location_id = 2100返回多条department_id,那么这条语句就是错误的,但是看给的选项没有这么一个,因此可以
认为它返回单条记录,因此选择B,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值