有疑问可以去itpub讨论:http://www.itpub.net/thread-1803800-1-1.html
查和104号员工同一个部门和同一个经理的所有员工的员工编号、姓名和部门。
hr@OCM> SELECTemployee_id,first_name,department_id
2 FROMemployees
3 WHERE (manager_id,department_id) = (SELECT department_id,manager_id FROM
4 employees
5 WHERE employee_id=104)
6 ANDemployee_id<.104;
no rows selected
用上面的语句,没有查出记录来。原来是什么呢?主要是where条件这里的子查询的操作符或字段的顺序写错了!我们来分析答案:
答案A是把这语句改成:exists的语法不是这样写的,明显不对!!!
hr@OCM> SELECTemployee_id,first_name,department_id
2 FROMemployees
3 WHERE (manager_id,department_id) exists (SELECT department_id,manager_idFROM
4 employees
5 WHERE employee_id=104)
6 ANDemployee_id<>104;
WHERE(manager_id,department_id) exists (SELECT department_id,manager_id FROM
*
ERROR at line 3:
ORA-00920: invalidrelational operator
答案B把这语句改成:结果显示无记录,其实这语法是没问题的,只是where条件主查询字段顺序不匹配,所以答案B不正确
hr@OCM> SELECTemployee_id,first_name,department_id
2 FROMemployees
3 WHERE (manager_id,department_id) in (SELECT department_id,manager_idFROM
4 employees
5 WHERE employee_id=104)
6 ANDemployee_id<>104;
no rows selected
答案C把这语句改成:结果显示无记录,其实这语法是没问题的,只是where条件主查询字段顺序不匹配,,所以答案C不正确
hr@OCM> SELECTemployee_id,first_name,department_id
2 FROMemployees
3 WHERE (manager_id,department_id) = any (SELECT department_id,manager_idFROM
4 employees
5 WHERE employee_id=104)
6 ANDemployee_id<>104;
no rows selected
答案D把这语句改成:显示三条记录,OK,那就是答案D,WHERE后面字段的顺序严格要和子查询里的字段顺序要一致。
hr@OCM> SELECTemployee_id,first_name,department_id
2 FROMemployees
3 WHERE (manager_id,department_id) = (SELECT manager_id,department_id FROM
4 employees
5 WHERE employee_id=104)
6 ANDemployee_id<>104;
EMPLOYEE_IDFIRST_NAME DEPARTMENT_ID
------------------------------- -------------
105 David 60
106 Valli 60
107 Diana 60
最后正确答案是选:D
QQ:252803295
学习交流QQ群:
DSI&Core Search Ⅰ 群:127149411(技术:已满) DSI&Core Search Ⅱ 群:177089463(技术:未满) DSI&Core Search Ⅲ 群:284596437(技术:未满) DSI&Core Search Ⅳ 群:192136702(技术:未满) DSI&Core Search Ⅴ 群:285030382(闲聊:未满)
MAIL:oracledba_cn@hotmail.com
BLOG: http://blog.csdn.net/guoyjoe
WEIBO:http://weibo.com/guoyJoe0218
ITPUB: http://www.itpub.net/space-uid-28460966.html
OCM: http://education.oracle.com/education/otn/YGuo.HTM