Updates to the newest season in scenario_package.sql
This commit is contained in:
parent
21e72a42cc
commit
5b507d3d65
@ -1,8 +1,8 @@
|
|||||||
--\timing
|
--\timing
|
||||||
--explain (analyze, buffers)
|
--explain (analyze, buffers)
|
||||||
WITH
|
WITH
|
||||||
mseq AS (
|
mseq AS (
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(
|
(
|
||||||
VALUES
|
VALUES
|
||||||
('01 - Jun',1)
|
('01 - Jun',1)
|
||||||
@ -36,7 +36,7 @@ FROM
|
|||||||
rlarp.osm_pool
|
rlarp.osm_pool
|
||||||
WHERE
|
WHERE
|
||||||
where_clause
|
where_clause
|
||||||
AND order_season IN (2021,2022)
|
AND order_season IN (2022,2023)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
order_season
|
order_season
|
||||||
,order_month
|
,order_month
|
||||||
@ -67,7 +67,7 @@ GROUP BY
|
|||||||
,CASE WHEN sum(value_usd) over () = 0 THEN 0 ELSE value_usd/sum(value_usd) over () END mix
|
,CASE WHEN sum(value_usd) over () = 0 THEN 0 ELSE value_usd/sum(value_usd) over () END mix
|
||||||
FROM
|
FROM
|
||||||
basket1
|
basket1
|
||||||
ORDER BY
|
ORDER BY
|
||||||
mix DESC
|
mix DESC
|
||||||
)
|
)
|
||||||
,months AS (
|
,months AS (
|
||||||
@ -94,14 +94,14 @@ GROUP BY
|
|||||||
SELECT
|
SELECT
|
||||||
order_month
|
order_month
|
||||||
,seq
|
,seq
|
||||||
,SUM(units) FILTER (WHERE order_season = 2021) "2021 qty"
|
,SUM(units) FILTER (WHERE order_season = 2022) "2022 qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 base qty"
|
,SUM(units) FILTER (WHERE order_season = 2023 AND iter IN ('copy','short ship','bad_ship','plan')) "2023 base qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj qty"
|
,SUM(units) FILTER (WHERE order_season = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj qty"
|
||||||
,SUM(units) FILTER (WHERE order_season = 2022) "2022 tot qty"
|
,SUM(units) FILTER (WHERE order_season = 2023) "2023 tot qty"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2021) "2021 value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter IN ('copy','short ship','bad_ship','plan')) "2022 base value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2023 AND iter IN ('copy','short ship','bad_ship','plan')) "2023 base value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2022 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2022 adj value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2023 AND iter NOT IN ('copy','short ship','bad_ship','plan')) "2023 adj value_usd"
|
||||||
,SUM(value_usd) FILTER (WHERE order_season = 2022) "2022 tot value_usd"
|
,SUM(value_usd) FILTER (WHERE order_season = 2023) "2023 tot value_usd"
|
||||||
FROM
|
FROM
|
||||||
months
|
months
|
||||||
GROUP BY
|
GROUP BY
|
||||||
@ -113,14 +113,14 @@ GROUP BY
|
|||||||
,mlist AS (
|
,mlist AS (
|
||||||
SELECT
|
SELECT
|
||||||
mseq.m order_month
|
mseq.m order_month
|
||||||
,"2021 qty"
|
,"2022 qty"
|
||||||
,"2022 base qty"
|
,"2023 base qty"
|
||||||
,"2022 adj qty"
|
,"2023 adj qty"
|
||||||
,"2022 tot qty"
|
,"2023 tot qty"
|
||||||
,"2021 value_usd"
|
,"2022 value_usd"
|
||||||
,"2022 base value_usd"
|
,"2023 base value_usd"
|
||||||
,"2022 adj value_usd"
|
,"2023 adj value_usd"
|
||||||
,"2022 tot value_usd"
|
,"2023 tot value_usd"
|
||||||
FROM
|
FROM
|
||||||
mseq
|
mseq
|
||||||
LEFT OUTER JOIN mpvt ON
|
LEFT OUTER JOIN mpvt ON
|
||||||
@ -147,12 +147,12 @@ GROUP BY
|
|||||||
doc->>'tag' tag
|
doc->>'tag' tag
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm_log
|
rlarp.osm_log
|
||||||
WHERE
|
WHERE
|
||||||
doc ? 'tag'
|
doc ? 'tag'
|
||||||
AND id <> 1
|
AND id <> 1
|
||||||
UNION
|
UNION
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(VALUES
|
(VALUES
|
||||||
('price'),
|
('price'),
|
||||||
('volume')
|
('volume')
|
||||||
) x(tag)
|
) x(tag)
|
||||||
@ -168,7 +168,7 @@ GROUP BY
|
|||||||
bill_cust_descr
|
bill_cust_descr
|
||||||
,ship_cust_descr
|
,ship_cust_descr
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
jsonb_build_object(
|
jsonb_build_object(
|
||||||
'months'
|
'months'
|
||||||
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
|
,(SELECT jsonb_agg(row_to_json(months)::jsonb) FROM months)
|
||||||
|
Loading…
Reference in New Issue
Block a user