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
|
return query
|
||||||
select
|
select
|
||||||
bl.bank_name, bl.account_type, bl.account_number, bl.friendly_name as account_friendly_name
|
bl.account_bank_name, bl.account_type, bl.account_number, bl.account_friendly_name
|
||||||
, bl.trx_date as transaction_date, bl.trx_description as transaction_description, bl.trx_amount as transaction_amount
|
, bl.transaction_date, bl.transaction_description, bl.transaction_amount
|
||||||
, bl.day_of_week as transaction_day_of_week, bl.running_bal
|
, bl.transaction_day_of_week, bl.running_bal
|
||||||
from public.runbal bl
|
from public.runbal bl
|
||||||
where
|
where
|
||||||
lower(bl.friendly_name) = trim(lower(p_account_name))
|
lower(bl.account_friendly_name) = trim(lower(p_account_name))
|
||||||
and bl.trx_date between p_start and p_end;
|
and bl.transaction_date between p_start and p_end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ drop table if exists public.accounts cascade;
|
|||||||
|
|
||||||
CREATE TABLE public.accounts(
|
CREATE TABLE public.accounts(
|
||||||
acct_id serial,
|
acct_id serial,
|
||||||
bank_name varchar(50) not null,
|
acct_bank_name varchar(50) not null,
|
||||||
account_type varchar(50) not null,
|
acct_type varchar(50) not null,
|
||||||
account_number varchar(20) null,
|
acct_number varchar(20) null,
|
||||||
friendly_name varchar(50) null,
|
acct_friendly_name varchar(50) null,
|
||||||
insert_dt_tm timestamp null default now(),
|
insert_dt_tm timestamp null default now(),
|
||||||
PRIMARY KEY( acct_id )
|
PRIMARY KEY( acct_id )
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ union all
|
|||||||
select 'Detail' as TBL, count(1) as REC_CNT from public.budgetdetails;
|
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
|
from
|
||||||
public.budgetdetails trx
|
public.budgetdetails trx
|
||||||
inner join public.accounts acct using(acct_id)
|
inner join public.accounts acct using(acct_id)
|
||||||
group by acct.friendly_name
|
group by acct.acct_friendly_name
|
||||||
|
|
||||||
|
|
||||||
select
|
select
|
||||||
acct.friendly_name
|
acct.acct_friendly_name
|
||||||
, extract(year from trx.trx_date) trx_year
|
, extract(year from trx.trx_date) trx_year
|
||||||
, lower(trx.trx_description) trx_description
|
, lower(trx.trx_description) trx_description
|
||||||
, avg(abs(trx.trx_amount))::numeric(7,2) avg_amt
|
, avg(abs(trx.trx_amount))::numeric(7,2) avg_amt
|
||||||
@@ -27,36 +27,35 @@ from
|
|||||||
where
|
where
|
||||||
trx.trx_date <= current_date
|
trx.trx_date <= current_date
|
||||||
and abs(trx.trx_amount) > 0
|
and abs(trx.trx_amount) > 0
|
||||||
-- and lower(acct.friendly_name) like '%savings'
|
-- and lower(acct.account_friendly_name) like '%savings'
|
||||||
group by
|
group by
|
||||||
trx_year, acct.friendly_name, lower(trx_description)
|
trx_year, acct.acct_friendly_name, lower(trx_description)
|
||||||
having
|
having
|
||||||
count(1) > 2
|
count(1) > 2
|
||||||
order by
|
order by
|
||||||
trx_year desc
|
trx_year desc
|
||||||
, acct.friendly_name
|
, acct.acct_friendly_name
|
||||||
, rec_cnt desc
|
, rec_cnt desc
|
||||||
, lower(trx.trx_description);
|
, lower(trx.trx_description);
|
||||||
|
|
||||||
|
|
||||||
select
|
select
|
||||||
bal.friendly_name
|
bal.account_friendly_name
|
||||||
, bal.trx_date
|
, bal.transaction_date
|
||||||
, bal.day_of_week
|
, bal.transaction_day_of_week
|
||||||
, age(trx_date, current_date) as days_from_today
|
, age(transaction_date, current_date) as days_from_today
|
||||||
, bal.trx_description
|
, bal.transaction_description
|
||||||
, bal.trx_amount
|
, bal.transaction_amount
|
||||||
, bal.running_bal
|
, bal.running_bal
|
||||||
from
|
from
|
||||||
public.runbal bal
|
public.runbal bal
|
||||||
where
|
where
|
||||||
lower(account_type) = 'checking'
|
lower(account_friendly_name) = 'joint checking'
|
||||||
and trx_date between
|
and transaction_date between
|
||||||
(current_date - interval '1 week')
|
(current_date - interval '1 week')
|
||||||
and (
|
and (
|
||||||
current_date + interval '3 weeks'
|
current_date + interval '3 weeks'
|
||||||
)::date
|
)::date
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ drop view if exists public.runbal;
|
|||||||
create view public.runbal
|
create view public.runbal
|
||||||
as
|
as
|
||||||
select
|
select
|
||||||
acct.bank_name
|
acct.acct_bank_name as account_bank_name
|
||||||
, acct.account_type
|
, acct.acct_type as account_type
|
||||||
, acct.account_number
|
, acct.acct_number as account_number
|
||||||
, acct.friendly_name
|
, acct.acct_friendly_name as account_friendly_name
|
||||||
, trx.trx_date
|
, trx.trx_date as transaction_date
|
||||||
, trx.trx_description
|
, trx.trx_description as transaction_description
|
||||||
, trx.trx_amount::numeric(8,2)
|
, trx.trx_amount::numeric(8,2) as transaction_amount
|
||||||
, to_char(trx.trx_date, 'day') day_of_week
|
, to_char(trx.trx_date, 'day') transaction_day_of_week
|
||||||
, sum(trx.trx_amount)
|
, sum(trx.trx_amount)
|
||||||
over(
|
over(
|
||||||
partition by trx.acct_id
|
partition by trx.acct_id
|
||||||
|
|||||||
Reference in New Issue
Block a user