From 7a73748b2a7f7d006648b0970a3c19bd286887bd Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 5 Aug 2025 20:14:52 -0400 Subject: [PATCH] start working on pulling history by part group and data segment --- new_targets/scripts/make_hist.ms.sql | 56 +++++++++++++++------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/new_targets/scripts/make_hist.ms.sql b/new_targets/scripts/make_hist.ms.sql index ad930a9..ec5afa7 100644 --- a/new_targets/scripts/make_hist.ms.sql +++ b/new_targets/scripts/make_hist.ms.sql @@ -3,32 +3,36 @@ -------------------------------------------------------------------------------- DELETE FROM pricing.lastprice; - -WITH srt AS ( - SELECT - customer, - mold, - part, - version, - qty, - ROUND(sales_usd / qty, 5) AS price, - odate, - oseas, - ordnum, - quoten, - ROW_NUMBER() OVER ( - PARTITION BY customer, mold, part, version - ORDER BY odate DESC - ) AS rn - FROM rlarp.osm_stack - WHERE - --quotes can't be integrated until we have datasegment or correct part code - version IN ('Actual'/*,'Quotes'*/) AND - customer IS NOT NULL AND - fs_line = '41010' AND - calc_status <> 'CANCELLED' AND - qty <> 0 AND - mold <> '' +WITH +--------SORT-------- +srt AS ( + SELECT + "Customer" customer, + "Part Group" partgroup, + i.v1ds dataseg, + "Data Source" version, + "Units" qty, + ROUND(sales_usd / qty, 5) AS price, + odate, + oseas, + ordnum, + quoten, + ROW_NUMBER() OVER ( + PARTITION BY customer, mold, part, version + ORDER BY odate DESC + ) AS rn + FROM + rlarp.osm_stack_pretty o + INNER JOIN CMSInterfaceIn.[CMS.CUSLG].ITEMM i ON + i.item = o.part + WHERE + --quotes can't be integrated until we have datasegment or correct part code + version IN ('Actual'/*,'Quotes'*/) AND + customer IS NOT NULL AND + fs_line = '41010' AND + calc_status <> 'CANCELLED' AND + qty <> 0 AND + mold <> '' ), json_rows AS ( SELECT