From a494709cc5047e51342b258310e557c39ffc7993 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Thu, 9 Mar 2023 20:24:58 -0500 Subject: [PATCH] made data element names more consistent --- .../functions/get_transactions_for_period.sql | 13 +++----- postgres/tables/accounts.sql | 8 ++--- postgres/temp.sql | 33 +++++++++---------- postgres/views/runbal.sql | 16 ++++----- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/postgres/functions/get_transactions_for_period.sql b/postgres/functions/get_transactions_for_period.sql index 97ec84d..9ca347e 100644 --- a/postgres/functions/get_transactions_for_period.sql +++ b/postgres/functions/get_transactions_for_period.sql @@ -26,16 +26,13 @@ raise notice 'INPUT: % p_start = %; % p_end = %;', E'\n', p_start, E'\n', p_end; return query select - bl.bank_name, bl.account_type, bl.account_number, bl.friendly_name as account_friendly_name - , bl.trx_date as transaction_date, bl.trx_description as transaction_description, bl.trx_amount as transaction_amount - , bl.day_of_week as transaction_day_of_week, bl.running_bal + bl.account_bank_name, bl.account_type, bl.account_number, bl.account_friendly_name + , bl.transaction_date, bl.transaction_description, bl.transaction_amount + , bl.transaction_day_of_week, bl.running_bal from public.runbal bl where - lower(bl.friendly_name) = trim(lower(p_account_name)) - and bl.trx_date between p_start and p_end; - - - + lower(bl.account_friendly_name) = trim(lower(p_account_name)) + and bl.transaction_date between p_start and p_end; end; $$; diff --git a/postgres/tables/accounts.sql b/postgres/tables/accounts.sql index a569248..c9e660c 100644 --- a/postgres/tables/accounts.sql +++ b/postgres/tables/accounts.sql @@ -2,10 +2,10 @@ drop table if exists public.accounts cascade; CREATE TABLE public.accounts( acct_id serial, - bank_name varchar(50) not null, - account_type varchar(50) not null, - account_number varchar(20) null, - friendly_name varchar(50) null, + acct_bank_name varchar(50) not null, + acct_type varchar(50) not null, + acct_number varchar(20) null, + acct_friendly_name varchar(50) null, insert_dt_tm timestamp null default now(), PRIMARY KEY( acct_id ) ); diff --git a/postgres/temp.sql b/postgres/temp.sql index d0fda91..e890cb7 100644 --- a/postgres/temp.sql +++ b/postgres/temp.sql @@ -5,15 +5,15 @@ union all select 'Detail' as TBL, count(1) as REC_CNT from public.budgetdetails; -select acct.friendly_name, count(1) as "Number of Transactions" +select acct.acct_friendly_name, count(1) as "Number of Transactions" from public.budgetdetails trx inner join public.accounts acct using(acct_id) -group by acct.friendly_name +group by acct.acct_friendly_name select - acct.friendly_name + acct.acct_friendly_name , extract(year from trx.trx_date) trx_year , lower(trx.trx_description) trx_description , avg(abs(trx.trx_amount))::numeric(7,2) avg_amt @@ -27,36 +27,35 @@ from where trx.trx_date <= current_date and abs(trx.trx_amount) > 0 --- and lower(acct.friendly_name) like '%savings' +-- and lower(acct.account_friendly_name) like '%savings' group by - trx_year, acct.friendly_name, lower(trx_description) + trx_year, acct.acct_friendly_name, lower(trx_description) having count(1) > 2 order by trx_year desc - , acct.friendly_name + , acct.acct_friendly_name , rec_cnt desc , lower(trx.trx_description); - + select - bal.friendly_name - , bal.trx_date - , bal.day_of_week - , age(trx_date, current_date) as days_from_today - , bal.trx_description - , bal.trx_amount + bal.account_friendly_name + , bal.transaction_date + , bal.transaction_day_of_week + , age(transaction_date, current_date) as days_from_today + , bal.transaction_description + , bal.transaction_amount , bal.running_bal from public.runbal bal where - lower(account_type) = 'checking' - and trx_date between + lower(account_friendly_name) = 'joint checking' + and transaction_date between (current_date - interval '1 week') and ( current_date + interval '3 weeks' - )::date - + )::date ; diff --git a/postgres/views/runbal.sql b/postgres/views/runbal.sql index 33a5188..c76e8f4 100644 --- a/postgres/views/runbal.sql +++ b/postgres/views/runbal.sql @@ -3,14 +3,14 @@ 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 + acct.acct_bank_name as account_bank_name + , acct.acct_type as account_type + , acct.acct_number as account_number + , acct.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, 'day') transaction_day_of_week , sum(trx.trx_amount) over( partition by trx.acct_id