case语句:
case when .... then .... when ... then ... else .... end

解决方案 »

  1.   

    你逻辑有点问题:
      A.a1 Not NULL AND B.b1 NOT NULL 、A.a2 is null、A.a3 = 'AAA'有可能重复,你到底要返回什么值
      

  2.   

    select 
    decode(
    instr(a3,'AAA')*length(a3),3,'3',
    decode(
    nvl(a2,1),1,'2',
    decode(
    nvl(a1,1),a1,
    decode(
    nvl(b1,1),b1,'0',1,'1')
    )
    )
    )
    from ...
      

  3.   

    此处a4字段相当于楼主表中的b1字段15:41:14 SQL> select * from d;A1    A2    A3    A4
    ----- ----- ----- -----
    1     2     AAA   4
    1           3     4
    1     2     3     4
    1     2     3实际:70
    15:41:22 SQL> select decode(instr(a3,'AAA')*length(a3),3,'3',decode(nvl(a2,1),1,'2',
    15:41:26   2  decode(nvl(a1,1),a1,decode(nvl(a4,1),a4,'0',1,'1')
    15:41:26   3  ))) from d;D
    -
    3
    2
    0
    1实际:80
    15:41:26 SQL>
      

  4.   

    谢谢楼上各位的热心   这里果然好人多 ^_^
    to : jiezhi(西域浪子)   
    case 好像不行,因为数值实现不知道具体是多少,只能区分空或者非空 
    to :w_tsinghua() 
    逻辑没有问题,如果数据没有错误,A.a1 Not NULL AND B.b1 NOT NULL 、A.a2 is null、A.a3 = 'AAA'  不会有重复数据to: bzszp(SongZip) 
    你的方法我试试看,我也想应该用decode,但是我没有写出来
    ps:你以前回答过我得问题,不过不是这个帐号,我想一定许多人都接受过你的帮助 再次感谢大家!
      

  5.   

    select decode(a.a3,'AAA','3',
             decode(a.a2,null,'2',
               decode(b.b1,null,
                 decode(A.a1,null,'unknown','1'), 
                 decode(A.a1,null,'unknown','0') ) ) ) from a, b