tps/loan_bal.pgsql
2017-10-24 17:37:20 -04:00

13 lines
326 B
PL/PgSQL

\timing
SELECT
r.*,
SUM(r."Advances"+r."Adjustments"-r."Payments") OVER (ORDER BY r."Post Date" asc ,r."Reference #" asc)
FROM
tps.trans
LEFT JOIN LATERAL jsonb_populate_record(null::tps.pnco, rec) r ON TRUE
WHERE
rec @> '{"Loan#":"606780191"}'
ORDER BY
r."Post Date" asc
,r."Reference #" asc