select a.type,a.quantity -b.quantity
(select a.type,sum(a.quantity) quantity from A1 a group by a.type ) a inner join
(select b.type,sum(b.quantity) quantity from B1 b group by b.type) b
on a.type=b.type
(select a.type,sum(a.quantity) quantity from A1 a group by a.type ) a inner join
(select b.type,sum(b.quantity) quantity from B1 b group by b.type) b
on a.type=b.type
(select type,sum(quantity) quantity from A1 group by type ) a inner join
(select type,sum(quantity) quantity from B1 group by type) b
on a.type=b.type
from(
select a.type,sum(a.quantity) as a_quqntity from A1 a group by a.type) a
,(select b.type,sum(b.quantity) as b_quantity from B1 b group by b.type) b
were a.type=b.type
(select a.type,sum(a.quantity) quantity from A1 a group by a.type ) aa inner join
(select b.type,sum(b.quantity) quantity from B1 b group by b.type) bb
on a.type=b.type
(select a.type,sum(a.quantity) quantity from A1 a group by a.type ) aa inner join
(select b.type,sum(b.quantity) quantity from B1 b group by b.type) bb
on aa.type=bb.type
(select a.type,sum(a.quantity) quantity from A1 a group by a.type ) a inner join
(select b.type,sum(b.quantity) quantity from B1 b group by b.type) b
on a.type=b.type这样应该可以了。