mirror of
https://github.com/acedanger/budget-database.git
synced 2025-12-05 22:50:13 -08:00
made data element names more consistent
This commit is contained in:
@@ -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;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -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 )
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user