select A ,B (select D fron table where *在这里如果查询出来的A=‘1’或A=‘2’后面判断的语句不一样,例如A='1'就执行number=100。 A=‘2’就去执行number=200*) as C  from  F
不知道这个怎么实现的。

解决方案 »

  1.   


    select A ,B, (select D from table where number= A*100) as C from F
    你要的大概是这个意思??
      

  2.   

    如果在sql语句判断,简单的可以使用decocde函数
    复杂的判断,可以使用case函数SQL> select * from tt;
     
           VAL
    ----------
             1
             2
             3
           100
     
    SQL> 
    SQL> SELECT decode(tt.val, 1, 'one', 2, 'two', 3, 'three', 'other') FROM tt;
     
    DECODE(TT.VAL,1,'ONE',2,'TWO',
    ------------------------------
    one
    two
    three
    other
    SQL> SELECT CASE
      2           WHEN tt.val = 1 THEN
      3            'one'
      4           WHEN tt.val = 2 THEN
      5            'two'
      6           WHEN tt.val = 3 THEN
      7            'three'
      8           ELSE
      9            'other'
     10         END
     11    FROM tt;
     
    CASEWHENTT.VAL=1THEN'ONE'WHENT
    ------------------------------
    one
    two
    three
    other
     
    SQL> 
      

  3.   

    如果根据A得到的情况,后面的判断语句比较多呢
    例如如果是1就执行这个sql      AND LOCAL_CODE = L05.LOCAL_CODE
               AND SHOP_CODE = L05.SHOP_CODE
    。。如果是2
    也可以像你那样用吗
      

  4.   

    select A ,B (select D fron table where *在这里如果查询出来的A=‘1’或A=‘2’后面判断的语句不一样,例如A='1'就执行number=100。 A=‘2’就去执行number=200*) as C from Fselect  case when A='1' then 100  when A='2' then 200*X else ... end  number from  table
      

  5.   


    select A,B,
          (select D fron table where (t.A='1' and number=100) or (t.A='2' and number=200))
      from table_name t
    ;
      

  6.   

    select f.A,f.B,C=case when f.A=1 then 100 when f.A=2 then 200*X else ... end number from F f;

    select f.A,f.B,decode(f.C,1,'number=100',2,'number=200*') from F f;