
/*
truncate table budgetdetails;

CALL public.import_budget_from_csv();
CALL public.update_budget_from_import();
*/


select 
	lower(trxdescription) trxdescription
	, avg(abs(trxamount)) avg_amt
	, min(abs(trxamount)) min_amt
	, max(abs(trxamount)) max_amt
	, count(trxdescription) rec_cnt
from
	public.budgetdetails b
where 
	trxdate <= current_date
	and abs(trxamount) > 0
group by
	lower(trxdescription)
having
	count(1) > 2
order by
	rec_cnt desc
	, trxdescription;


select 
	bal.trxdate
	, bal.day_of_week
	, age(trxdate, current_date) as days_from_today
	, bal.trxdescription
	, bal.trxamount
	, bal.runningbal
from
	public.runbal bal
where 
	trxdate between current_date and (
		current_date + interval '2 weeks'
	)::date
;

select * from budgetimport b 
where dt like '2023-03%'
