try to use the function decode

解决方案 »

  1.   

    不好意思,没有说清楚
    type1和type2原来的数值并不是2、4、0,只不过select时用decode转的
      

  2.   

    select case when isnull(b.id,'不存在')='不存在' then 0 else case when a.add='China' then 2 else 4 end end
    from table2 a,
         table3 b
    where a.id =(*) b.id
      

  3.   

    谢谢ORARichard(没钱的日子......) 用过decode了
    不过没完全写出来...
      

  4.   

    看错了,以为是sqlserver,呵呵select decode (b.id is null, 0(Decode a.add='China',2,4)) as type1
    from table2 a,
         table3 b
    where a.id =(+) b.id
      

  5.   

    SELECT TABLE2.TYPE2 FROM TABLE2 WHERE EXISTS (SELECT 1 FROM TABLE1 WHERE TABLE1.ID = TABLE2.ID AND TABLE1.TYPE1 <> TABLE2.TYPE2)
      

  6.   

    --no test,tryselect b.type2 from
    (
      select id,decode(typm,'G',2,4) type1 from tb1
    ) a,
    (
      select id,decode(tb2.add,'China',2,4)*decode(tb3.id,null,0,1) type2 from tb2,tb3
      where tb2.id=tb3.id(+)
    ) b
    where a.id=b.id and a.type1<>b.type2
      

  7.   

    --no test,retryselect b.type2 from
    (
      select id,decode(typm,'G',2,4) type1 from tb1
    ) a,
    (
      select tb2.id,decode(tb2.add,'China',2,4)*decode(tb3.id,null,0,1) type2 from tb2,tb3
      where tb2.id=tb3.id(+)
    ) b
    where a.id=b.id and a.type1<>b.type2