数据库 两张表

解决方案 »

  1.   

    with t as(
    select 1 te1,3 rent,'AAAA' ac from dual
    union all
    select 2 te1,12 rent,'AAAA' ac from dual
    union all
    select 3 te1,2 rent,'BBBB' ac from dual
    union all
    select 4 te1,6 rent,'CCCC' ac from dual),
    s as(
    select 1 te1,12 f1,3 f2,7 f3 from dual
    union all
    select 2 te1,11 f1,6 f2,12 f3 from dual
    union all
    select 3 te1,4 f1,1 f2,11 f3 from dual
    )
    select ac,sum(rent),NVL(sum(f1),0) f1 ,NVL(sum(f2),0) F2,NVL(sum(f3),0) F3
    from t,s
    where t.te1=s.te1(+)
    group by ac
      

  2.   

    select a.account,sum(a.rent),sum(nvl(b.f1,0)),sum(nvl(b.f2,0)),sum(nvl(b.f3,0)) from A a,B b where a.tel=b.tel(+) group by a.account;
      

  3.   

    select sum(rent) as rent,acount,sum(f1) as f1,sum(f2) as f2,sum(f3) as f3 
    from dbo.A 
    left join dbo.B on A.tel =B.tel 
    group by acount这个是sqlserver的 ,挺简单的呀
      

  4.   

    select a.account,sum(a.rent),sum(nvl(b.f1,0)),sum(nvl(b.f2,0)),sum(nvl(b.f3,0)) from A a,B b where a.tel=b.tel(+) group by a.account;
    基础