问题描述
下面,我将描述将要使用的所有表。
第一个表是我们必须计算成本的基本表。
Del_Line表
第二个表是Outbound_Cost_Table
第三张表包含一列,该列具有每个国家/地区的计算城市 plant_code
计算表
可能会有更多的国家和城市采用不同的工厂代码和计算方法。 我想做的是编写通用查询来计算每个交货行的出站成本,因为计算表将是动态的,并且可由业务用户随时更新。
with cte as (
Select A.plant_code,B.Cost/(Sum(A.Packs)*2) cost_per_pack
from #del_line A left join Outbound_Cost B
on A.dl_plant_code = B.Plant_code and A.city = B.City
group by A.[DL_Plant_Code],B.Cost
)
Select A.*,B.cost_per_pack*A.Packs*2 as Outbound_Handling_Cost
from #del_line A left join CTE B
On A.dl_plant_code = B.dl_plant_code
在以上查询中,我正在为达拉斯进行计算。
我想要这样的东西
with cte as (
Select A.plant_code,C.Calc cost_per_pack
from #del_line A left join Outbound_Cost B
on A.dl_plant_code = B.Plant_code and A.city = B.City left Join #Calc C on A.Market = C.Market and C.kpi = 'Outbound Handling'and C.kpi_level = 'Delivery Line'
group by A.[DL_Plant_Code],C.calc as Outbound_Handling_Cost
from #del_line A left join CTE B
On A.dl_plant_code = B.dl_plant_code left Join #Calc C on A.Market = C.Market and C.Handling = 'Outbound Handling' and C.[KPI Level] = 'Delivery Line Drilldown'
由于基表del_line非常大,请避免使用循环。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)