两表,
A 表(订单)
order style customer qty
1000 22 33 10
1000 22 33 -4
1000 22 33 -1
1000 44 33 8
1000 44 33 -4
B表(已出货)
order style customer qty
1000 22 33 2
1000 22 33 1
1000 44 33 3
想得到以下剩余量
order style customer qty
1000 22 33 2
1000 44 33 1
谢谢!
SQL code:
select a.order,a.style,a.customer,(sum(a.qty)-sum(b.qty)) qty
from a,b
where a.order=b.order,a.style=b.style,a.customer=b.customer
group by a.order,a.style,a.customer
SQL code:
select a.order,a.style,a.customer, (a.qty-b.qty) as [qty]
from (select order,style,cusomer,sum(qty) as qty
from tb_a
group by order,style,cusomer) a left join (select order,style,cusomer,sum(qty) as qty
from tb_b
group by order,style,cusomer)b
on a.order=b.order and a.style=b.style and a.customer=b.customer
我发现我是最笨的