我想写出类似这种的SQL,该如何写,哪位高人给个思路先   
select * from table where 
when 条件1:表达式1-表达式2>=0
when 条件2:表达式1-表达式2>0         

解决方案 »

  1.   

    表达式1 > 表达式2
    and 
    (case when  条件1 then 表达式1-表达式2 ) = 0
      

  2.   

    表达式1 > 表达式2
    and 
    (case when 条件1 then 表达式1-表达式2 else 0 end ) = 0
      

  3.   

    给你个例子参考一下
    SQL> select * from t4;
     
           ID1        ID2
    ---------- ----------
             1          2
             3          2
             5          2
             2          2
             7          2
             7          2
     
    6 rows selected
     
    SQL> select * from t4 where id1=(case when id1=7 then id1 else id2 end);
     
           ID1        ID2
    ---------- ----------
             2          2
             7          2
             7          2
     
    SQL>