如我有表
订单
ID 部门ID  订单号  是否公开 
1  1       A1      0
2  1       A2      1
3  2       A3      1
4  2       A4      2
5  2       A5      2是否公开定义为:0:不公开,1:部门公开,2:公开现在我以部门人员进行查询,那么应该显示2,3,4,5
select * from 订单 where 是否公开 <>  0 and (如果是否公开为1时,判断部门ID==2,不然不进行判断 )谢谢

解决方案 »

  1.   

    select * from 订单 where (是否公开 =1 and 部门ID=2) or 是否公开>1
      

  2.   

    select * from 订单 where 是否公开<>0 and case when 是否公开=1 then 部门ID=2 else 1=1 end 详细可以看:
    http://blog.csdn.net/dba_huangzj/article/details/7684520
      

  3.   


    -->你自己不是差不多都写出来了么?
    select * from 订单 where 是否公开>1 or (是否公开=1 and 部门ID=2)
      

  4.   

    select * from 订单 where 是否公开<>0 
    and 部门ID=case when 是否公开=1 then 2 else 部门ID end