stringsql=$@" SELECT MAX( a.OrderNo) as OrderNo,MAX(b.GoodsName) as GoodsName,b.Specification,MAX(b.Unit_Price) as Unit_Price,SUM(b.Number) as Number,'供应商名称' as SupplierName,
SUM(b.Final_Price) as Final_Price,SUM(b.FreightMoney) as FreightMoney,SUM(b.Final_Price+b.FreightMoney) as AllPrice ,
SUM(IFNULL(b.CostMoney,0)*b.Number) as CostMoney,0 as PackingMoney, 0 as CostFreight,0 as GoodsFreight,
c.OneCommission,d.TwoCommission,0 as OtherPrice,e.ALLCommission,0 as Paid
from rb_goods_orderdetail as b
LEFT JOIN rb_goods_order as A on a.OrderId=b.OrderId
LEFT JOIN (SELECT SUM(Commission) as OneCommission,OrderId from rb_goods_ordercommission where Grade=1 and CommissionState=2 GROUP BY OrderId ) as c on a.OrderId=c.OrderId
LEFT JOIN (SELECT SUM(Commission) as TwoCommission,OrderId from rb_goods_ordercommission where Grade=2 and CommissionState=2 GROUP BY OrderId ) as d on a.OrderId=d.OrderId
LEFT JOIN (SELECT SUM(Commission) as ALLCommission,OrderId from rb_goods_ordercommission GROUP BY OrderId ) as e on a.OrderId=e.OrderId {where}