有三张表
表a
id kind name
1 水果 苹果
2 水果 香蕉表b
id in_num in_date
1 10000 2013-02-01
2 1000 2013-02-01
1 10000 2013-02-02
表c
id out_num out_date
1 100 2013-02-20
1 100 2013-02-21
怎么写sql语句,查询 结果为没种产品的汇总数,没有的为空 kind,name,in_num,out_num
水果 苹果 20000 200
水果 香蕉 1000 null写成select a.kind,a.name ,sum(b.in_num) as 入库总数 ,sum(c.out_num) as 出库总数 from a a,b b,c c where a.id=b.id(+) and a.id=c.id(+) and group by a.kind,a.name;但是执行出来结果不对,菜鸟寻求帮助,十分感谢!! sqloracle 查询连接查询
表a
id kind name
1 水果 苹果
2 水果 香蕉表b
id in_num in_date
1 10000 2013-02-01
2 1000 2013-02-01
1 10000 2013-02-02
表c
id out_num out_date
1 100 2013-02-20
1 100 2013-02-21
怎么写sql语句,查询 结果为没种产品的汇总数,没有的为空 kind,name,in_num,out_num
水果 苹果 20000 200
水果 香蕉 1000 null写成select a.kind,a.name ,sum(b.in_num) as 入库总数 ,sum(c.out_num) as 出库总数 from a a,b b,c c where a.id=b.id(+) and a.id=c.id(+) and group by a.kind,a.name;但是执行出来结果不对,菜鸟寻求帮助,十分感谢!! sqloracle 查询连接查询
select *,(select sum(in_num) from b where b.id=a.id) 入库总数,(select sum(out_num) from c where c.id=a.id) 出库总数 from a
from 表A left join (select id,sum(in_num) as in_num from 表B group by id )as b on 表A.id=b.id left join (select id,sum(out_num) as out_num from 表C group by id)as c on 表A.id=c.id