tps/loan_bal.pgsql
2017-10-19 11:20:52 -04:00

13 lines
319 B
PL/PgSQL

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