在where条件中使用逻辑运算符: or and not
1 查询10号部门或者20部门的员工信息
1 | select * from emp where deptno=10 or deptno=20; |
2 查询10号部门员工工资为1300的员工信息
1 | select * from emp where deptno=10 and sal=1300; |
3 查询81年2月(含2月)至82年2月(不含2月)入职的员工信息(大于等于81年2月1日,小于等于82年1月31日)
1 | 说明: 注意日期格式问题,注意月份单月不要在前面加0,否则会报错 |
结论: 关于and or 操作符的sql优化问题?
1 | where条件在进行逻辑表达式计算的时候,是从右往左进行的, 所以对于and来说, 要把容易出现假的放在 |
4 查询奖金为空的员工信息-null
1 | select * from emp where comm=null; --不正确的写法 |
5 查询奖金不为空的员工信息
1 | select * from emp where comm!=null; |
分析下面的sql语句:
1 | select * from emp where deptno=10 or deptno=30 and sal=1250; |