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

View File

@ -208,14 +208,29 @@ WHERE
SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0 SELECT * FROM baseline WHERE (SELECT COUNT(*) FROM volume_only) = 0
) )
,pscale AS ( ,pscale AS (
----what if the selection has several value columns, which one to use?----- SELECT
SELECT
(SELECT pincr FROM target) AS target_increment (SELECT pincr FROM target) AS target_increment
,sum("Amount") AS value ,sum($$||format('%I',_value_col)||') AS value'||$$
,CASE WHEN (SELECT vscale. ,CASE WHEN (SELECT sum($$||format('%I',_value_col)||$$) FROM volume) = 0 THEN
((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume) --if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN 0 ELSE (SELECT pincr FROM target)/sum("Amount") FROM volume END factor 0
FROM 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 volume
) )
,pricing AS ( ,pricing AS (
@ -232,7 +247,7 @@ INSERT INTO
SELECT SELECT
* *
FROM FROM
volume volume_only
UNION ALL UNION ALL
SELECT SELECT
* *