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

解决方案 »

  1.   

    select a.type,a.quantity-b.quantity from (select type,sum(quantity) quantity  from A1 group by type) a ,(select type,sum(quantity) quantity  from B1 group by type) b where a.type=b.type
      

  2.   

    select a.type,a.quantity -b.quantity 
    (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
      

  3.   

    select a.type,a_quqntity-b.quantity as quqntity
    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
      

  4.   

    select aa.type,aa.quantity -bb.quantity from 
    (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
      

  5.   

    select aa.type,aa.quantity -bb.quantity from 
    (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
      

  6.   

    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这样应该可以了。