swap out fb_qty or units
This commit is contained in:
parent
610c78f36f
commit
994b076321
@ -2,9 +2,9 @@ WITH
|
|||||||
target AS (select target_vol vincr, target_prc pincr)
|
target AS (select target_vol vincr, target_prc pincr)
|
||||||
,testv AS (
|
,testv AS (
|
||||||
SELECT
|
SELECT
|
||||||
sum(fb_qty) tot
|
sum(units) tot
|
||||||
,sum(fb_qty) FILTER (WHERE iter = 'copy') base
|
,sum(units) FILTER (WHERE iter = 'copy') base
|
||||||
,sum(fb_qty) FILTER (WHERE module = 'new basket') newpart
|
,sum(units) FILTER (WHERE module = 'new basket') newpart
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_pool
|
rlarp.osm_pool
|
||||||
WHERE
|
WHERE
|
||||||
@ -139,8 +139,8 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,vscale AS (
|
,vscale AS (
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT vincr::numeric FROM target) incr
|
(SELECT vincr::numeric FROM target) incr
|
||||||
,(SELECT sum(fb_qty)::numeric FROM basemix) base
|
,(SELECT sum(units)::numeric FROM basemix) base
|
||||||
,(SELECT vincr::numeric FROM target)/(SELECT sum(fb_qty)::numeric FROM basemix) factor
|
,(SELECT vincr::numeric FROM target)/(SELECT sum(units)::numeric FROM basemix) factor
|
||||||
)
|
)
|
||||||
--select * from vscale
|
--select * from vscale
|
||||||
,volume AS (
|
,volume AS (
|
||||||
@ -205,7 +205,7 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,b.ddqtsi --0
|
,b.ddqtsi --0
|
||||||
,b.fgqshp --0
|
,b.fgqshp --0
|
||||||
,b.diqtsh --0
|
,b.diqtsh --0
|
||||||
,b.fb_qty*s.factor fb_qty
|
,b.units*s.factor units
|
||||||
,b.fb_cst_loc*s.factor fb_cst_loc
|
,b.fb_cst_loc*s.factor fb_cst_loc
|
||||||
,b.fb_cst_loc_cur*s.factor fb_cst_loc_cur
|
,b.fb_cst_loc_cur*s.factor fb_cst_loc_cur
|
||||||
,b.fb_cst_loc_fut*s.factor fb_cst_loc_fut
|
,b.fb_cst_loc_fut*s.factor fb_cst_loc_fut
|
||||||
@ -252,7 +252,7 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,(b.fb_val_loc*s.factor*r_rate)::numeric value_usd
|
,(b.fb_val_loc*s.factor*r_rate)::numeric value_usd
|
||||||
,(b.fb_cst_loc*s.factor)::numeric cost_loc
|
,(b.fb_cst_loc*s.factor)::numeric cost_loc
|
||||||
,(b.fb_cst_loc*s.factor*c_rate)::numeric cost_usd
|
,(b.fb_cst_loc*s.factor*c_rate)::numeric cost_usd
|
||||||
,(b.fb_qty*s.factor)::numeric units
|
,(b.units*s.factor)::numeric units
|
||||||
FROM
|
FROM
|
||||||
basemix b
|
basemix b
|
||||||
CROSS JOIN vscale s
|
CROSS JOIN vscale s
|
||||||
@ -271,7 +271,7 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
,CASE WHEN (SELECT sum(fb_val_loc * r_rate) FROM volume) = 0 THEN
|
||||||
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume)) <> 0 THEN
|
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume)) <> 0 THEN
|
||||||
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply
|
||||||
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(fb_qty) FROM volume)
|
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc * r_rate) FROM volume))/(SELECT sum(units) FROM volume)
|
||||||
ELSE
|
ELSE
|
||||||
0
|
0
|
||||||
END
|
END
|
||||||
@ -342,13 +342,13 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,b.ddqtsi --0
|
,b.ddqtsi --0
|
||||||
,b.fgqshp --0
|
,b.fgqshp --0
|
||||||
,b.diqtsh --0
|
,b.diqtsh --0
|
||||||
,0 fb_qty
|
,0 units
|
||||||
,0 fb_cst_loc
|
,0 fb_cst_loc
|
||||||
,0 fb_cst_loc_cur
|
,0 fb_cst_loc_cur
|
||||||
,0 fb_cst_loc_fut
|
,0 fb_cst_loc_fut
|
||||||
--,b.fb_val_loc*s.factor fb_val_loc
|
--,b.fb_val_loc*s.factor fb_val_loc
|
||||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc
|
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric fb_val_loc
|
||||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl
|
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.fb_val_loc_pl*s.factor END)::numeric fb_val_loc_pl
|
||||||
--,b.fb_val_loc_pl*s.factor fb_val_loc_pl
|
--,b.fb_val_loc_pl*s.factor fb_val_loc_pl
|
||||||
,b.calc_status --0
|
,b.calc_status --0
|
||||||
,b.flag --0
|
,b.flag --0
|
||||||
@ -387,8 +387,8 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
,b.mod_chansub
|
,b.mod_chansub
|
||||||
,b.quota_rep_descr
|
,b.quota_rep_descr
|
||||||
,b.director_descr
|
,b.director_descr
|
||||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc
|
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price/b.r_rate ELSE b.fb_val_loc*s.factor END)::numeric value_loc
|
||||||
,(CASE WHEN s.factor = 0 THEN b.fb_qty * s.mod_price ELSE b.fb_val_loc*s.factor*b.r_rate END)::numeric value_usd
|
,(CASE WHEN s.factor = 0 THEN b.units * s.mod_price ELSE b.fb_val_loc*s.factor*b.r_rate END)::numeric value_usd
|
||||||
,0 cost_loc
|
,0 cost_loc
|
||||||
,0 cost_usd
|
,0 cost_usd
|
||||||
,0 units
|
,0 units
|
||||||
@ -398,7 +398,7 @@ target AS (select target_vol vincr, target_prc pincr)
|
|||||||
WHERE
|
WHERE
|
||||||
s.factor <> 0 or s.mod_price <> 0
|
s.factor <> 0 or s.mod_price <> 0
|
||||||
)
|
)
|
||||||
--select sum(value_usd), sum(fb_qty) from pricing
|
--select sum(value_usd), sum(units) from pricing
|
||||||
, ins AS (
|
, ins AS (
|
||||||
INSERT INTO rlarp.osm_pool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
|
INSERT INTO rlarp.osm_pool (SELECT * FROM pricing UNION ALL SELECT * FROM volume) RETURNING *
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user