oracle数据库中对三个不同的字段进行求和,来自两张不同的表

解决方案 »

  1.   

    用加号直接加不就行了?

    select A.a + B.b + C.c from A, B, C
      

  2.   

    select to_number(nvl(A.a,0)) + to_number(nvl(B.b,0)) + to_number(nvl(C.c ,0))from A, B, C
      

  3.   


    SQL> with t1 as(
      2       select 1 t1_id,10 t1_col_1,'ddd' t_n from dual union all
      3       select 3,15,'eeee' from dual union all
      4       select 5,78,'ttt' from dual union all
      5       select 8,89,'yyy' from dual)
      6  ,t2 as(
      7      select 1 t2_id,100 t2_col_1,456 t2_col_2 from dual union all
      8      select 2,200,300 from dual union all
      9      select 3,400,500 from dual union all
     10      select 8,1,1 from dual)
     11  select a.t1_id , a.t1_col_1 + b.t2_col_1 + b.t2_col_2
     12  from t1 a,t2 b
     13  where a.t1_id=b.t2_id
     14  /     T1_ID A.T1_COL_1+B.T2_COL_1+B.T2_COL
    ---------- ------------------------------
             1                            566
             3                            915
             8                             91