select *,y.amount1 from 人员表 a 
left join
(select b.id,sum(b.缴费金额) as amount1 from 人员缴费表 b group by b.id) y
on a.id=y.id 
left join
(select c.id,sum(c.消费金额) as amount2 from 人员消费表 c group by c.id) z
on a.id=z.id

解决方案 »

  1.   

    select a.*,y.amount1,z.amount2 from 人员表 a 

    (select b.id,sum(b.缴费金额) as amount1 from 人员缴费表 b group by b.id) y
    ,
    (select c.id,sum(c.消费金额) as amount2 from 人员消费表 c group by c.id) z
    where a.ID = y.id(+) and a.ID = z.id(+)
      

  2.   

    正确的 不过 Oracle 8i 似乎不支持 Left Join,所以我 来印证一下我的写法。
      

  3.   

    我一直搞不清Oracle 的(+)形式的连接方式。
    是不是 where a.ID = y.id(+)  那么 A 表中的所有行出现,Y表中符合的行出现,不符合的填NULL?
      

  4.   

    left join 是sql 2标准的写法,oracle9就支持了
      

  5.   

    select a.*,nvl(y.amount1,0),nvl(z.amount2,0) from  a 
    left join
    (select b.id,sum(b.fee) as amount1 from  b group by b.id) y
    on a.id=y.id 
    left join
    (select c.id,sum(c.fee2) as amount2 from  c group by c.id) z
    on a.id=z.id
    这样更完美