//string tsql = @"select count(1) count from [dbo].[TemuChengBen] a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join JC_UserInfo c on a.mUserId=c.UserId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=1 ) t group by t.GoodsId ) t1 on a.GoodsId=t1.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=2 ) t group by t.GoodsId ) t2 on a.GoodsId=t2.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=3 ) t group by t.GoodsId ) t3 on a.GoodsId=t3.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=7 ) t group by t.GoodsId ) t7 on a.GoodsId=t7.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=14 ) t group by t.GoodsId ) t14 on a.GoodsId=t14.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 ) t group by t.GoodsId ) t30 on a.GoodsId=t30.GoodsId left join (select a.GoodsId,sum(GoodsHJNum) as GoodsHJNum,LeftNumW= sum(isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0)), LeftNumE=sum(isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0) ) from HW_GoodsDetail a inner join [TemuChengBen] b on a.goodsid=b.GoodsId group by a.GoodsId) sumall on a.GoodsId=sumall.GoodsId"
stringtsql=@"select ShopName,sum(GrossProfit) as GrossProfit from (