forecast_api/build/act_to_fcst/snap_cost_current.sql

44 lines
881 B
MySQL
Raw Normal View History

2020-06-09 18:35:52 -04:00
BEGIN;
WITH
plist AS (
SELECT DISTINCT
part
,plnt
FROM
rlarp.osmfs_dev
-----prevent a list of fake parts
INNER JOIN lgdat.stka ON
v6part = part
AND v6plnt = plnt
)
,clist AS (
SELECT
p.part
,p.plnt
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs) stdcost
FROM
plist p
LEFT OUTER JOIN lgdat.icstm im ON
im.cgpart = p.part
AND im.cgplnt = p.plnt
LEFT OUTER JOIN lgdat.icstp ip ON
ip.chpart = p.part
AND ip.chplnt = p.plnt
LEFT OUTER JOIN lgdat.icstr ir ON
ir.y0part = p.part
AND ir.y0plnt = p.plnt
)
UPDATE
rlarp.osmfs_dev o
SET
fb_cst_loc_cur = c.stdcost * o.fb_qty
FROM
clist c
WHERE
c.part = o.part
AND c.plnt = o.plnt;
--AND version = 'b21';
commit;