forecast_api/route_sql/list_changes.sql
2020-02-25 00:27:30 -05:00

29 lines
675 B
SQL

WITH
agg as (
SELECT
ol.doc->>'user' "user"
,quota_rep_descr
,ol.doc->>'stamp' stamp
,ol.doc->>'tag' tag
,ol.doc->>'message' "comment"
,jsonb_pretty(ol.doc) doc
,ol.id
,to_char(round(sum(value_usd),2),'$999,999,999D00') sales
from
rlarp.osm_log ol
inner join rlarp.osm_pool on
id = logid
WHERE
quota_rep_descr = 'replace_user'
AND tag <> 'Initial Build'
group BY
ol.doc->>'user'
,quota_rep_descr
,ol.doc->>'stamp'
,ol.doc->>'tag'
,ol.doc->>'comment'
,jsonb_pretty(ol.doc)
,ol.id
)
SELECT
jsonb_agg(row_to_json(agg)::jsonb ORDER BY agg.stamp desc) x from agg