From 88b0760e6df67798ce2759cefc53631aa4819acd Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 29 Aug 2024 13:34:50 -0400 Subject: [PATCH] reporting --- database/reports/dcard_bal.sql | 2 +- database/reports/hunt_bal.sql | 2 +- database/reports/stacked.sql | 64 ++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 database/reports/stacked.sql diff --git a/database/reports/dcard_bal.sql b/database/reports/dcard_bal.sql index 65b7e06..3629f7f 100644 --- a/database/reports/dcard_bal.sql +++ b/database/reports/dcard_bal.sql @@ -3,6 +3,6 @@ SELECT r.* ,SUM(r."Amount") OVER (ORDER BY r."Post Date" asc , r."Description") + 1083.50 balance FROM - tpsv.dcard_default r + tpsv.dcard_mapped r ORDER BY r."Post Date" desc diff --git a/database/reports/hunt_bal.sql b/database/reports/hunt_bal.sql index 81c4604..4e65798 100644 --- a/database/reports/hunt_bal.sql +++ b/database/reports/hunt_bal.sql @@ -3,6 +3,6 @@ SELECT r.* ,SUM(r."Amount") OVER (ORDER BY r."Date" asc , r.id) + 29909.75 balance FROM - tpsv.hunt_default r + tpsv.hunt_mapped r ORDER BY r."Date" desc diff --git a/database/reports/stacked.sql b/database/reports/stacked.sql new file mode 100644 index 0000000..98c1d94 --- /dev/null +++ b/database/reports/stacked.sql @@ -0,0 +1,64 @@ +with +dcard AS ( + SELECT + 'dcard' srce + ,r.id + ,r.logid + --,r."Trans. Date" + ,r."Post Date" + ,r."Description" + ,r."Amount" + ,r."Category" + ,r."Party" + ,r."Reason" + ,SUM(r."Amount") OVER (ORDER BY r."Post Date" asc , r."Description") + 1083.50 balance + FROM + tpsv.dcard_mapped r + ORDER BY + r."Post Date" desc +) +,hunt as ( + SELECT + 'hunt' srce + ,r.id + ,r.logid + --,r."Reference Number" + --,r."Payee Name" + ,r."Date" + ,r."Memo" + ,r."Amount" + ,r."Cateogry Name" + ,r."Party" + ,r."Reason" + ,SUM(r."Amount") OVER (ORDER BY r."Date" asc , r.id) + 29909.75 balance + FROM + tpsv.hunt_mapped r + ORDER BY + r."Date" desc +) +,chase AS ( + SELECT + 'chase' srce + ,r.id + ,r.logid + --,r."Trans Date" + ,r."Post Date" + ,r."Description" + ,-r."Amount" "Amount" + ,r."Type" + ,null::text "Party" + ,null::text "Reason" + ,SUM(-r."Amount") OVER (ORDER BY r."Post Date" asc , r.id) + 374.23 balance + FROM + tpsv.chase_default r + ORDER BY + r."Post Date" desc +) +,stacked AS ( +SELECT * FROM dcard +UNION ALL +SELECT * FROM hunt +UNION ALL +SELECT * FROM chase +) +select * from stacked order by "Post Date" desc