您的位置:首页 > 产品设计 > UI/UE

OCP 1Z0 051 QUESTION NO: 23

2014-06-03 11:33 453 查看
QUESTION NO: 23

Evaluate this SQL statement:

SELECT e.emp_name, d.dept_name

FROM employees e

JOIN departments d

USING (department_id)

WHERE d.department_id NOT IN (10,40)

ORDER BY dept_name;

The statement fails when executed. Which change fixes the error?

A. remove the ORDER BY clause

B. remove the table alias prefix from the WHERE clause

C. remove the table alias from the SELECT clause

D. prefix the column in the USING clause with the table alias

E. prefix the column in the ORDER BY clause with the table alias

F. replace the condition

”d.department_id NOT IN (10,40)”

in the WHERE clause with

”d.department_id <> 10 AND d.department_id <> 40”

Answer: C,E

DROP TABLE employees PURGE;
CREATE TABLE employees
AS
SELECT e.first_name || '' || e.last_name AS emp_name, e.department_id
FROM hr.employees e
WHERE rownum <= 5;

DROP TABLE departments PURGE;
CREATE TABLE departments AS
SELECT d.department_name AS dept_name, d.department_id
FROM hr.departments d;
当join中使用using子句时,using里出现的列,在整个查询中都不能加前缀。

所以答案应该是B

SQL> SELECT e.emp_name, d.dept_name
  2    FROM employees e
  3    JOIN departments d
  4   USING (department_id)
  5   WHERE d.department_id NOT IN (10, 40)
  6   ORDER BY dept_name;
SELECT e.emp_name, d.dept_name
  FROM employees e
  JOIN departments d
 USING (department_id)
 WHERE d.department_id NOT IN (10, 40)
 ORDER BY dept_name
ORA-25154: column part of USING clause cannot have qualifier


SQL> SELECT e.emp_name, d.dept_name
2    FROM employees e
3    JOIN departments d
4   USING (department_id)
5   WHERE department_id NOT IN (10, 40)
6   ORDER BY dept_name;
EMP_NAME                                      DEPT_NAME
--------------------------------------------- ------------------------------
PatFay                                        Marketing
MichaelHartstein                              Marketing
DouglasGrant                                  Shipping
DonaldOConnell                                Shipping
4 rows selected
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: