drop view if exists public.runbal;

create view public.runbal 
as 
select
	acct.bank_name
	, acct.account_type 
	, acct.account_number 
	, acct.friendly_name
	, trx.trx_date
	, trx.trx_description
	, trx.trx_amount::numeric(8,2) 
	, to_char(trx.trx_date, 'day') 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
				) running_bal 
from
	public.budgetdetails trx
	join public.accounts acct using (acct_id)
