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表

解决方案 »

  1.   

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

  2.   


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

  3.   

    not (sal > 1500 and comm is not null);  应该是 sal<=1500 or comm is null
      

  4.   

    按照题意  应该是sal<=1500 and comm is null
    离散数学的问题 呵呵
      

  5.   

    这种基本知识都出错的东西也叫教材,直接扔了下载本sql reference
      

  6.   

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

  7.   

    离散数学有类似的例子 
    !(A&B) = !A OR !B