要根据表中的两个字段来添加一个字段,
比如字段a,字段b,添加字段c
a = 0 并且b = 0 c = 1
a = 0 并且b = 1 c = 2
a = 1 并且b = 1 c = 3求教

解决方案 »

  1.   


    select case when a =0 and b=0 then 1
    when a =0 and b=1 then 2
    when a =1 and b=1 then 3
    end c from table;
      

  2.   


    create table t1 (a number(10),b number(10));insert into t1 values (1,1);
    insert into t1 values (0,1); 
    insert into t1 values (0,0); select a,b,
           case when a=0 and b=0 then 1
                when a=0 and b=1 then 2 
                when a=1 and b=1 then 3 
           end c 
    from t1    a    b    c
    ---------------------------
    1 1 1 3
    2 0 1 2
    3 0 0 1
      

  3.   


    with t as
    (select 0 a,0 b from dual
    union all
    select 0,1 from dual
    union all
    select 1,1 from dual
    )select a,b,a+b+1 c from t;
             A          B          C
    ---------- ---------- ----------
             0          0          1
             0          1          2
             1          1          3