isolate price change on no volume adjustment

This commit is contained in:
Paul Trowbridge 2022-04-12 02:09:36 -04:00
parent 0e904c1631
commit d5c2980bb1
1 changed files with 25 additions and 10 deletions

View File

@ -208,15 +208,30 @@ WHERE
SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0
)
,pscale AS (
----what if the selection has several value columns, which one to use?-----
SELECT
(SELECT pincr FROM target) AS target_increment
,sum("Amount") AS value
,CASE WHEN (SELECT vscale.
((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume)
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN 0 ELSE (SELECT pincr FROM target)/sum("Amount") FROM volume END factor
FROM
volume
SELECT
(SELECT pincr FROM target) AS target_increment
,sum($$||format('%I',_value_col)||') AS value'||$$
,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
0
ELSE
--expects inbound partial adjustment from volume table
--if the volume table does not have enough price added, need to get to goal increment
--multiplying by the raw factor without adding 1 will work since this data set will be added to the volume data set
((SELECT pincr FROM target)-(SELECT sum($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_value_col)||$$) FROM volume)
END factor
,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum($$||format('%I',_value_col)||$$) FROM volume)) <> 0 THEN
--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($$||format('%I',_value_col)||$$) FROM volume))/(SELECT sum($$||format('%I',_units_col)||$$) FROM volume)
ELSE
0
END
ELSE
0
END mod_price
FROM
volume
)
,pricing AS (
SELECT
@ -232,7 +247,7 @@ INSERT INTO
SELECT
*
FROM
volume
volume_only
UNION ALL
SELECT
*