我有 3 表库存,向内,问题
库存表的列和数据:
part_no | part_name | totalqty
10100 ciol 30
112233 abc 20
123456 coper 50
向内表:
part_no | qty
123456 10
123456 20
10100 20
112233 15
10100 25
问题表:
part_no | qty
112233 20
112233 15
123456 10
112233 25
10100 40
10100 20
我想要的输出:
part_no | part_name |inwardQty |issueQty
10100 coil 45 60
112233 abc 15 60
123456 coper 30 10
以下是我写的查询,但没有给出我想要的输出
select s.part_no,s.part_name,sum(i.qty) as inwardQty,sum(p.qty)as issueQty
from stock s
left join inward i on s.part_no = i.part_no
left join issue p on s.part_no = p.part_no
group by
s.part_no,s.part_name
通过此查询获得以下输出:
part_no | part_name |inwardQty |issueQty
10100 coil 90 120
112233 abc 45 60
123456 coper 30 20