select ProduceID,sum(Quantity),sum(Unit),sum(price),sum(Total) from details a inner join orders b on a.orderno=b.orderNo where b.isinput=1 group by ProduceID
Select a.ProduceID,
sum(case when b.IsInput = 1 then a.Quantity else 0 end) as 入库数量,
sum(case when b.IsInput = 1 then a.Quantity * a.price else 0 end) as 入库金额,
sum(case when b.IsInput = 0 then a.Quantity else 0 end) as 出库数量,
sum(case when b.IsInput = 0 then a.Quantity * a.price else 0 end) as 出库金额
from Details a
join Orders b on a.OrderNo = b.OrderNo
group by a.ProduceID