图1-8 查询结果4
(5)查询部门编号为10的所有经理,和部门编号为20的所有销售员的详细资料:
分析:这道题的难点在于查询的两个部分之间是与的关系还是或的关系,题目表明将部门为10的所有经理,部门为20的所有销售员都查询出来,那么他们之间的关系必然是或的关系。对应的sql语句是:select * from emp where deptno=10 and job=’经理’ or deptno=20 and job=’销售员’,查询结果如图1-9所示:

图1-9 查询结果5
(6) 查询部门编号为10的所有经理,部门编号为20的所有销售员,还有即不是经理又不是销售员但其工资大或等于20000的所有员工详细资料:
分析:这条题的逻辑与第五题的逻辑是一样的,都是或的关系;对应的sql语句是:select * from emp where deptno=10 and job=’经理’ or deptno=20 and job=’销售员’ or job not in(‘经理’,’销售员’) and sal>=20000,查询结果如图1-10所示:

图1-10 查询练习6
(7)查询无奖金或奖金低于1000的员工,对应sql语句是:select * from emp where comm is null or comm<1000,查询结果如图1-11所示:

图1-11 查询练习7
(8)查询名字由三个字组成的员工,对应sql语句是:select * from emp where ename like ‘___’,查询结果如图1-12所示:

本文版权归黑马程序员Java培训学院所有,欢迎转载,转载请注明作者出处。谢谢!
作者:黑马程序员Java培训学院
首发:http://javaee.itheima.com/