日期:2014-05-18 浏览次数:20785 次
-----订单数量统计列表 select coOrder.OrderID, SUM(coOrderDetail.Qty) AS [订单数量],SUM(stInstoreDetail.Qty) AS [入库数量] From coOrder INNER JOIN coOrderDetail ON coOrder.OrderNo=coOrderDetail.OrderNo INNER JOIN pmOrder ON coOrder.OrderID =pmOrder.OrderID INNER JOIN stInstoreDetail ON pmOrder.OrderNO=stInstoreDetail.OrderNo WHERE coOrder.OrderID='20120101' GROUP BY coOrder.OrderID --------------------------------------- orderID 订单数量 入库数量 20120101 4857 10400 实际正确的入库数量应该为:5200
select coOrder.OrderID, coOrderDetail.Qty AS [订单数量],stInstoreDetail.Qty AS [入库数量] From coOrder INNER JOIN (select OrderNo,SUM(Qty) as Qty from coOrderDetail group by OrderNo) as coOrderDetail ON coOrder.OrderNo=coOrderDetail.OrderNo INNER JOIN pmOrder ON coOrder.OrderID =pmOrder.OrderID INNER JOIN (select OrderNo,SUM(Qty) as Qty from stInstoreDetail group by OrderNo) as stInstoreDetail ON pmOrder.OrderNO=stInstoreDetail.OrderNo WHERE coOrder.OrderID='20120101' GROUP BY coOrder.OrderID