forecast_api/route_sql/list_changes.sql

37 lines
868 B
MySQL
Raw Normal View History

2020-02-14 02:24:52 -05:00
WITH
list AS materialized (
2019-03-23 17:17:46 -04:00
SELECT
2020-02-14 02:24:52 -05:00
l.doc->>'user' "user",
jsonb_path_query_first(l.doc,'$.scenario.quota_rep_descr')->>0 quota_rep_descr,
to_char((l.doc->>'stamp')::timestamptz,'YYYY-MM-DD HH:MI:SS') "stamp",
l.doc->>'message' "comment",
jsonb_pretty(l.doc) def,
l.id
2019-03-23 17:17:46 -04:00
FROM
2020-02-14 02:24:52 -05:00
rlarp.osm_log l
2019-03-23 17:17:46 -04:00
WHERE
2020-02-14 02:24:52 -05:00
l.doc @? '$.scenario.quota_rep_descr ? (@ == replace_user)'
)
,agg as (
SELECT
list.user
,list.quota_rep_descr
,list.stamp
,list.comment
,list.def
,list.id
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
from
LIST
inner join rlarp.osm_pool on
id = logid
group BY
list.user
,list.quota_rep_descr
,list.stamp
,list.comment
,list.def
,list.id
2019-03-23 17:17:46 -04:00
)
SELECT
2020-02-14 02:24:52 -05:00
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg