8AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAo9GuKPMDY0aemO4cp96DtgAAAAAIAAAARABUAFMAAAAQZgAAAAEAACAAAACWsFAvy7Ru5cBmIP8MdIwbk7kyLj/tRBQQcYO/olFXmQAAAAAOgAAAAAIAACAAAABw5sjuCIuWqSQa3IbC0eMYqzPYQ0jBDgj6PcTcdf3GuzAAAAAxctj7NvRswxI2FqdAVyHKbb7b2z+iI2TBKanSA7vnmYVQUksSxKwJ1Tyj+zy7xzFAAAAA1hFdtbmKkoEco8dvFtCdGdxYpCUxGZuxPAjeceBcc0csbU+5mL9jBhB9e0QI9jJ5ZU58bLFKMnxxRD8s0LDPrwAQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAo9GuKPMDY0aemO4cp96DtgAAAAAIAAAARABUAFMAAAAQZgAAAAEAACAAAACkvLYGDQmgyiVFIhFUT2g4xDIQ/UrMovUI45Lp9hvjFwAAAAAOgAAAAAIAACAAAACW++6Ayl/64i8p+HeIhCSQjSLImVoDwHVliHKCMS7xiTAAAAD4ZvN6df2eujsflm3dNwOqJv8mPcPrgM/kGqfWiIc8ph+6cYhDaToOiwThB4Ggs1dAAAAAMHgyQKRDfqoYSi/KyjWA1G9/qPUOif3N2b1fXV7D77nP3p9QwlsGqzbq2fjv51EDuuYO+5hsBsGypwhSt8gmmg1/1/20220SET DATEFIRST 1
select fb.产品类型,fb.渠道名称,fb.实际派送渠道,fb.所属客户,fb.业务员,fb.分公司名称,
CONVERT(nvarchar(10),称重时间, 120) as Weight_Time,
CONVERT(nvarchar(10),称重时间, 120) as 称重时间,
max(convert(varchar(7),称重时间,120) + '第'+ cast((datepart(wk,称重时间) - datepart(wk,convert(varchar(7),称重时间,120) + '-01') + 1) as varchar(2)) + '周')周,
sum(isnull(fb.称重重量,0)/1000.0) as 称重,
count(0) as 票数,
sum(isnull(bc.Profit,0)) as 毛利,
sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))收入,
sum(isnull(bc.ShippingFee,0)+isnull(bc.EUTariff,0)+isnull(bc.AttachFee,0))成本,
case when sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))=0
then 0 else sum(isnull(bc.Profit,0))/ sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))end 毛利占比
,sum(isnull(smpAmount.fee,0))实际成本
,case when sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))=0 or sum(isnull(smpAmount.fee,0))=0 then 0
else sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))-sum(isnull(smpAmount.fee,0)) end 实际毛利
,case when sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))=0 or sum(isnull(smpAmount.fee,0))=0 then 0 else (sum(isnull(mc.ShippingFee,0)+isnull(mc.EUTariff,0)+isnull(mc.AttachFee,0))-sum(isnull(smpAmount.fee,0)))/sum(isnull(smpAmount.fee,0)) end 实际毛利占比
from BaseOrderInfo fb
join Finance_Order_Charges(nolock) bc on fb.BranchCompanyId=bc.CustomerId and fb.系统单号=bc.SystemNo and bc.IncomeOrESxpense='支出' and bc.ChargeTarget=2 and bc.Offset=0
join Finance_Order_Charges(nolock) mc on fb.CustomerId=mc.CustomerId and fb.系统单号=mc.SystemNo and mc.IncomeOrESxpense='支出' and mc.ChargeTarget=1 and mc.Offset=0
left join (
select Number,sum(isnull(SettlementAmount,0)) as fee from xyy_smp.dbo.Compute_ExpenseAmount(nolock) ea
left join xyy_smp.dbo.Compute_ExpenseAmountBatchOperation (nolock) op on ea.BatchNo=op.BatchNo
where ea.BatchNo = op.BatchNo and ea.CostType=1
group by Number
)smpAmount on smpAmount.Number=fb.系统单号
where fb.称重时间>'2022-01-01' and PublicChannelId not in(8,9,15,16,21,32,35,40,42,43,54,55,56,63,64,65) and fb.CustomerId not in(227,294)
group by fb.产品类型,fb.渠道名称,fb.实际派送渠道,fb.所属客户,fb.业务员,fb.分公司名称,CONVERT(nvarchar(10),称重时间, 120)
order by fb.产品类型,fb.渠道名称,fb.实际派送渠道,fb.所属客户,fb.业务员,fb.分公司名称,CONVERT(nvarchar(10),称重时间, 120)936false2"LASTTIME:Input",{AFB8E866-2C0E-4E81-8A24-72DFF2845C1B};0[dbo].[BaseETLGroup]936false3falsefalseTABLOCK,CHECK_CONSTRAINTS2147483647DataSourceViewIDDataSourceViewIDTableInfoObjectTypeTable]]>