/* CALL public.import_budget_from_csv(); CALL public.update_budget_from_import(); select 'Import' as TBL, count(1) as REC_CNT from public.budgetimport union all select 'Detail' as TBL, count(1) as REC_CNT from public.budgetdetails; */ select lower(trx_description) trx_description , avg(abs(trx_amount))::numeric(7,2) avg_amt , count(trx_description) rec_cnt , min(abs(trx_amount))::numeric(7,2) min_amt , max(abs(trx_amount))::numeric(7,2) max_amt from public.budgetdetails b where trx_date <= current_date and abs(trx_amount) > 0 group by lower(trx_description) having count(1) > 2 order by rec_cnt desc , trx_description; select bal.trx_date , bal.day_of_week , age(trx_date, current_date) as days_from_today , bal.trx_description , bal.trx_amount , bal.running_bal from public.runbal bal where trx_date between current_date and ( current_date + interval '3 weeks' )::date ;