查询所有月薪不是3000与5000的员工的信息,为什么下面的写法不对?
 select * from emp where sal <> any(3000,5000); --查询不对select * from emp where sal not in(3000,5000); ---这可以
查询月薪是3000与5000的员工的信息。
select * from emp where sal =any(3000,5000); ---这可以
查询所有月薪不是3000与5000的员工的信息。
select * from emp where sal !=any(3000,5000);  ----这错误 ,为什么?

解决方案 »

  1.   

    你要明白一個道理,any是任意的,sal !=any(3000,5000); 也就是sal既不為3000,又不為5000,你認為這樣的數據能存在嗎,因此你選出來的還是全部信息
    如果你這樣寫
    select * from emp where sal !=any(5000);
    則5000的就被排除掉了,明白了?
      

  2.   


    --=用any <>用all
    select * from emp where sal<> all(3000,5000);
      

  3.   

    any与all的运用逻辑,lz理解了 就可以了
      

  4.   

    SQL code
    --=用any <>用all
    select * from emp where sal<> all(3000,5000);
     
    正解
      

  5.   

    换成not in(3000,5000);或者2楼说的,!=any();
     any,all,in很常用