Skip to content

Commit

Permalink
Update column order: account value then accout name
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Feb 19, 2020
1 parent 70bd1cb commit 30b6120
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ CREATE OR REPLACE FUNCTION ProfitAndLossReport(IN p_startDate timestamp,
IN p_endDate timestamp)
RETURNS TABLE
(
AccountName text,
AccountValue text,
AccountName text,
balance_three_years_ago numeric,
balance_two_years_ago numeric,
balance_one_year_ago numeric,
Expand All @@ -15,12 +15,13 @@ CREATE OR REPLACE FUNCTION ProfitAndLossReport(IN p_startDate timestamp,
AS
$BODY$

SELECT ev.name AccountName,
ev.value AccountValue,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '3 Year'::interval, p_endDate - '3 Year'::interval) balance_three_years_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '2 Year'::interval, p_endDate - '2 Year'::interval) balance_two_years_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '1 Year'::interval, p_endDate - '1 Year'::interval) balance_one_year_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate, p_endDate) current_balance
SELECT--
ev.value AccountValue,
ev.name AccountName,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '3 Year'::interval, p_endDate - '3 Year'::interval) balance_three_years_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '2 Year'::interval, p_endDate - '2 Year'::interval) balance_two_years_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate - '1 Year'::interval, p_endDate - '1 Year'::interval) balance_one_year_ago,
ProfitAndLossBalanceForAccountInPeriod(ev.c_elementvalue_id, p_startDate, p_endDate) current_balance
FROM c_elementvalue ev
WHERE TRUE
AND ev.accounttype IN ('E', 'R')
Expand Down

0 comments on commit 30b6120

Please sign in to comment.