From ea4d8213d46e12527b07f171995305769e947b8d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 18 Oct 2023 07:49:23 -0400 Subject: [PATCH] vault backup: 2023-10-18 07:49:23 --- sql/price_pool.sql | 39 ++++++++++++++++++++------------------- todo.md | 2 ++ 2 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 todo.md diff --git a/sql/price_pool.sql b/sql/price_pool.sql index fefe86b..77a4dea 100644 --- a/sql/price_pool.sql +++ b/sql/price_pool.sql @@ -10,7 +10,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( o.customer ,o.chanwide ,o.nursery_region - ,o.general_region + ,c.greenhouse_region ,m.part_group baseitem ,m.majg ,m.assc @@ -46,6 +46,8 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( AND tq.mold = i.stlc AND tq.chan = 'DISTRIB DROP SHIP' AND tq.data_segment = _ds.dataseg + LEFT OUTER JOIN rlarp.cust c ON + c.code = CASE o.chan WHEN 'DIR' THEN o.bill_cust ELSE o.ship_cust END WHERE o.version <> '6/1 Order Book' --AND o.part like 'SQL035%' @@ -57,7 +59,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( o.customer ,o.chanwide ,o.nursery_region - ,o.general_region + ,c.greenhouse_region ,m.part_group ,m.majg ,m.assc @@ -73,14 +75,13 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( SELECT jsonb_strip_nulls( jsonb_build_object( - 'customer' ,CASE WHEN GROUPING(customer ) = 0 THEN customer END - ,'chanwide' ,CASE WHEN GROUPING(chanwide ) = 0 THEN chanwide END - ,'nursery_region' ,CASE WHEN GROUPING(nursery_region ) = 0 THEN nursery_region END - ,'general_region' ,CASE WHEN GROUPING(general_region ) = 0 THEN general_region END - --,'country' ,CASE WHEN GROUPING(country) = 0 THEN country END - ,'baseitem' ,CASE WHEN GROUPING(baseitem ) = 0 THEN baseitem END - ,'v1dataseg' ,CASE WHEN GROUPING(v1dataseg) = 0 THEN v1dataseg END - ,'v0dataseg' ,CASE WHEN GROUPING(v0dataseg) = 0 THEN v0dataseg END + 'customer' ,CASE WHEN GROUPING(customer ) = 0 THEN customer END + ,'chanwide' ,CASE WHEN GROUPING(chanwide ) = 0 THEN chanwide END + ,'nursery_region' ,CASE WHEN GROUPING(nursery_region ) = 0 THEN nursery_region END + ,'greenhouse_region' ,CASE WHEN GROUPING(greenhouse_region ) = 0 THEN greenhouse_region END + ,'baseitem' ,CASE WHEN GROUPING(baseitem ) = 0 THEN baseitem END + ,'v1dataseg' ,CASE WHEN GROUPING(v1dataseg) = 0 THEN v1dataseg END + ,'v0dataseg' ,CASE WHEN GROUPING(v0dataseg) = 0 THEN v0dataseg END ) ) gset ,oseas @@ -93,14 +94,14 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( agg GROUP BY GROUPING SETS ( -- oseas baseitem v0datseg chanwide customer region v1dataseg -- - (oseas, baseitem, v0dataseg, customer ) - ,(oseas, baseitem, customer, v1dataseg ) - ,(oseas, baseitem, v0dataseg, chanwide ) - ,(oseas, baseitem, v0dataseg, chanwide, nursery_region ) - ,(oseas, baseitem, v0dataseg, chanwide, general_region ) - ,(oseas, baseitem, chanwide, v1dataseg ) - ,(oseas, baseitem, v0dataseg, nursery_region ) - ,(oseas, baseitem, v0dataseg, general_region ) + (oseas, baseitem, chanwide, v0dataseg, customer ) + ,(oseas, baseitem, chanwide, customer, v1dataseg ) + ,(oseas, baseitem, chanwide, v0dataseg ) + ,(oseas, baseitem, chanwide, v0dataseg, nursery_region ) + ,(oseas, baseitem, chanwide, v0dataseg, greenhouse_region ) + ,(oseas, baseitem, chanwide, v1dataseg ) + ,(oseas, baseitem, chanwide, v0dataseg, nursery_region ) + ,(oseas, baseitem, chanwide, v0dataseg, greenhouse_region ) ) ) SELECT @@ -129,7 +130,7 @@ CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS ( -- rlarp.price_pool g --WHERE -- o.version IN ('Actual','Quotes') --- AND g.gset = jsonb_build_object('baseitem',o.baseitem,'v0dataseg',o.v0dataseg,'chanwide','D','general_region','US'); +-- AND g.gset = jsonb_build_object('baseitem',o.baseitem,'v0dataseg',o.v0dataseg,'chanwide','D','greenhouse_region','US'); -- --UPDATE -- rlarp.osm_stack o diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..30f8092 --- /dev/null +++ b/todo.md @@ -0,0 +1,2 @@ +- [ ] label aggregation levels with a sort and a short label +- [ ] unwrap the data to the necessary level to get back to a table