Files
budget-database/postgres/views/runbal.sql

15 lines
719 B
SQL

-- public.runbal source
CREATE OR REPLACE VIEW public.runbal
AS SELECT acct.institution_name AS account_bank_name,
acct.acct_type AS account_type,
acct.acct_number AS account_number,
acct.friendly_name AS account_friendly_name,
trx.trx_date AS transaction_date,
trx.trx_description AS transaction_description,
trx.trx_amount::numeric(8,2) AS transaction_amount,
to_char(trx.trx_date::timestamp with time zone, 'day'::text) AS transaction_day_of_week,
sum(trx.trx_amount) OVER (PARTITION BY trx.acct_id ORDER BY trx.trx_date, trx.trx_amount DESC ROWS UNBOUNDED PRECEDING) AS running_bal,
trx.trx_id as transaction_id
FROM budgetdetails trx
JOIN accounts acct USING (acct_id);