drop view if exists public.runbal;

create view public.runbal 
as 
select
	acct.bank_name 
	, acct.account_type 
	, acct.account_number 
	, acct.friendly_name
	, det.trx_date
	, det.trx_description
	, det.trx_amount::numeric(8,2) 
	, to_char(det.trx_date, 'day') day_of_week
	, sum(det.trx_amount) over(
			order by
				det.trx_date
				, det.trx_amount desc rows unbounded preceding
			) running_bal
from
	public.budgetdetails det
	join public.accounts acct using (acct_id)
