diff --git a/offline/account_plug.sql b/offline/account_plug.sql index 52ad207..d964266 100644 --- a/offline/account_plug.sql +++ b/offline/account_plug.sql @@ -205,6 +205,7 @@ targ AS ( ,factor AS ( SELECT account + ,segment ,targv ,targm ,targc @@ -217,10 +218,11 @@ FROM targ t LEFT OUTER JOIN rlarp.osm_pool o ON o.billto_group = t.account - AND o.segm = 'Retail' + AND o.segm = t.segment AND o.order_season = 2022 GROUP BY account + ,segment ,targv ,targm ,targc @@ -232,8 +234,8 @@ GROUP BY rlarp.osm_log(doc) SELECT $${ - "message":"adjust select retail customers to targets sales and margin", - "tag":"retail", + "message":"force accounts to match target total value and margin", + "tag":"retail plug", "type":"build" }$$::jsonb doc RETURNING * @@ -298,8 +300,8 @@ GROUP BY s.account = o.billto_group CROSS JOIN log WHERE - order_season = 2022 - AND segm = 'Retail' + o.order_season = 2022 + AND o.segm = s.segment GROUP BY o.fspr ,o.plnt ---master data