From 3854bed603e3cffee447c307fd95314a1c9413da Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 13 Apr 2021 17:44:06 -0400 Subject: [PATCH] further isolate odd orders, create change log --- change_log.sql | 13 +++++++++++++ over_under_ship.sql | 28 +++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 change_log.sql diff --git a/change_log.sql b/change_log.sql new file mode 100644 index 0000000..5a22ae2 --- /dev/null +++ b/change_log.sql @@ -0,0 +1,13 @@ +WITH l AS ( + SELECT DISTINCT logid FROM rlarp.osm_pool +) +SELECT + doc->>'user' as user, + (doc->>'stamp')::timestamptz stamp, + CASE WHEN logid IS NULL THEN 'undone' ELSE '' END flag, + doc->>'tag', doc->>'message', + doc->'scenario'->>'quota_rep_descr' dsm +FROM + rlarp.osm_log + LEFT OUTER JOIN l ON logid = id +LIMIT 1000; diff --git a/over_under_ship.sql b/over_under_ship.sql index aec6a87..80aa929 100644 --- a/over_under_ship.sql +++ b/over_under_ship.sql @@ -1,15 +1,25 @@ SELECT - calc_status, - flag, - sum(fb_val_loc * r_rate) filter (where fb_qty < 0) overship, - sum(fb_val_loc * r_rate) filter (where fb_qty > 0) undership + calc_status + ,flag + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits + ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units FROM - rlarp.osm_dev + rlarp.osmf_dev WHERE - oseas = 2021 - AND version = 'ACTUALS' - AND calc_status = 'CLOSED' - AND flag = 'REMAINDER' + ( + ( + oseas = 2021 + AND odate <@ daterange('2020-06-01','2021-04-11') + ) + OR sseas = 2021 + ) + AND fs_line = '41010' + --AND version = 'ACTUALS' + --AND calc_status = 'CLOSED' + --AND flag = 'REMAINDER' GROUP BY calc_status, flag;