+ -
当前位置:首页 → 问答吧 → oracle查询小问题,拙计死我了,想不明白

oracle查询小问题,拙计死我了,想不明白

时间:2011-12-05

来源:互联网

1.查询出工资大于1500并且可以领奖金的雇员的信息
select * from emp where comm is not null and sal > 1500;


2.查询出工资不大于1500,并且不可以领奖金的雇员的信息。
select * from emp where not (sal > 1500 and comm is not null);//(教材上这么写的)查询结果明显有大于1500的
我觉得还可以这么写
select * from emp where sal<=1500 and comm is null;
但查询结果却不一样,WHY?我错了吗,where?

我逻辑弄错了吗?

表就是ORACLE的Scott用户下的EMP表

作者: runtime_error   发布时间: 2011-12-05

select * from emp where not (sal > 1500 and comm is not null);
这句表示的意思是 工资不大于1500 或者 可以领奖金。
SQL code

not (A and B) = not A or not B

作者: jianghshun   发布时间: 2011-12-05

引用 1 楼 jianghshun 的回复:
select * from emp where not (sal > 1500 and comm is not null);
这句表示的意思是 工资不大于1500 或者 可以领奖金。

SQL code

not (A and B) = not A or not B


谢谢你的回答,我还想问下,那如果不写成这种的,就第二个查询,写成
select * from emp where sal<=1500 and comm is null; 因该没错吧,那教材上的就与题意
不符了,是不?

作者: runtime_error   发布时间: 2011-12-05