我有以下 sql 语句:
select
a.desc
,sum(bdd.amount)
from t_main c
left outer join t_direct bds on (bds.repid=c.id)
left outer join tm_defination def a on (a.id =bds.sId)
where c.repId=1000000134
group by a.desc;
当我运行它时,我得到以下结果:
desc amount
NW 12.00
SW 10
当我尝试添加另一个左外连接以获取另一组值时:
select
a.desc
,sum(bdd.amount)
,sum(i.amt)
from t_main c
left outer join t_direct bds on (bds.repid=c.id)
left outer join tm_defination def a on (a.id =bdd.sId)
left outer join t_ind i on (i.id=c.id)
where c.repId=1000000134
group by a.desc;
它基本上将金额字段加倍,例如:
desc amount amt
NW 24.00 234.00
SE 20.00 234.00
结果应该是:
desc amount amt
NW 12.00 234.00
SE 10.00 NULL
我该如何解决?