物品   数量   进售
手提   22      进
电脑   20      进
手提   20      进
电脑   15      出
手提   25      出
电脑   10      进查询出如下
物品   进     出    剩余
手提   42     25    17
电脑   30     15    15

解决方案 »

  1.   

    字段名不要用中文。
    假如产品是product ,进货innum ,出货outnumselect 
        product,sum(innum),sum(outnum),sum(innum)-sum(outnum)
    from 
        producttable
    group by product
      

  2.   

    写得易懂点的话:
    select 名称,(select sum(数量) from 表 where 进售='进'),(select sum(数量) from 表 where 进售='出'),把两条语句相减  from 表 group by 名称