SELECT GdName,Type,BoxNo, Sum(case when InOutStatus=1 then Count else Count*-1 end) as Count from DataStocks --这个是求和 存的话是正数 ,取是负,相加就是箱子里面该物品的数量 WHERE BoxNo=1 GROUP BY GdName,Type,BoxNo;