clean up scenario package

This commit is contained in:
Trowbridge 2019-03-01 17:39:44 -05:00
parent aa67562d5b
commit 04b43a8f8d
2 changed files with 71 additions and 79 deletions

View File

@ -167,15 +167,11 @@ server.get('/scenario_package', bodyParser.json(), function (req, res) {
jsonb_build_object(
'months'
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
)
,jsonb_build_object(
'base'
,'base'
,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base)
)
,jsonb_build_object(
'totals'
,'totals'
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
)`
) package`
console.log(w);
Postgres.FirstRow(w, [], res)
//res.json("hi")

View File

@ -1,72 +1,68 @@
--\timing
--explain (analyze, buffers)
WITH base AS (
SELECT
order_season
,order_month
,version
,iter
,part_descr
,bill_cust_descr
,ship_cust_descr
,SUM(units) units
,SUM(value_usd) value_usd
FROM
rlarp.osm_fcpool
WHERE
quota_rep_descr = '90005 - MARK WILKINSON'
AND segm = 'Retail'
AND mod_chan = 'MASS'
AND order_month = 'May'
GROUP BY
order_season
,order_month
,version
,iter
,part_descr
,bill_cust_descr
,ship_cust_descr
)
,months AS (
SELECT
order_season
,version
,iter
,order_month
,sum(units) units
,sum(value_usd) value_usd
FROM
base
GROUP BY
order_season
,version
,iter
,order_month
)
,totals AS (
SELECT
order_season
,version
,iter
,sum(units) units
,sum(value_usd) value_usd
FROM
months
GROUP BY
order_season
,version
,iter
)
SELECT
jsonb_build_object(
'months'
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
)
,jsonb_build_object(
'base'
,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base)
)
,jsonb_build_object(
'totals'
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
)
\timing
--explain (analyze, buffers)
WITH base AS (
SELECT
order_season
,order_month
,version
,iter
,part_descr
,bill_cust_descr
,ship_cust_descr
,SUM(units) units
,SUM(value_usd) value_usd
FROM
rlarp.osm_fcpool
WHERE
quota_rep_descr = '90005 - MARK WILKINSON'
AND segm = 'Retail'
AND mod_chan = 'MASS'
AND order_month = 'May'
GROUP BY
order_season
,order_month
,version
,iter
,part_descr
,bill_cust_descr
,ship_cust_descr
)
,months AS (
SELECT
order_season
,version
,iter
,order_month
,sum(units) units
,sum(value_usd) value_usd
FROM
base
GROUP BY
order_season
,version
,iter
,order_month
)
,totals AS (
SELECT
order_season
,version
,iter
,sum(units) units
,sum(value_usd) value_usd
FROM
months
GROUP BY
order_season
,version
,iter
)
SELECT
jsonb_build_object(
'months'
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
,'base'
,(SELECT jsonb_agg(row_to_json(base)::jsonb) FROM base)
,'totals'
,(SELECT jsonb_agg(row_to_json(totals)::jsonb) FROM totals)
) package