I am brand spanking new to SQL and Stack Overflow. I am originally an accountant but have recently moved on to financial analytics. I am having trouble understanding how to write SQL to aggregate manually created items under a single column:
From the report draft attached, you'll see there is multiple lines for both Fringe and Other Direct Expenses, I want to make these single lines, but have been trying for weeks with no other help.
Here is my code:
SELECT
subjectarea1.ProjectName saw_0,
subjectarea1.PurchaseOrderAmount saw_1,
subjectarea1.ProjectID saw_2,
subjectarea1.BeginDate saw_3,
subjectarea1.EndDate saw_4,
subjectarea1.Indirect saw_5,
subjectarea2.Location saw_6,
subjectarea2.BudgetID saw_7,
subjectarea2.budgetamount saw_8,
subjectarea2.BudgetAcount saw_9,
subjectarea1.Credit saw_10,
subjectarea1.Debit saw_11,
subjectarea1.GLaccount saw_12,
subjectarea1.Debit - subjectarea1.Credit saw_13,
subjectarea2.budgetamount - (subjectarea1.Debit - subjectarea1.Credit) saw_14,
subjectarea1.Account_Category saw_15,
subjectarea2.Account_Category2 saw_16,
REPORT_AGGREGATE("subjectarea1"."Debit"-"subjectarea1"."Credit" BY "subjectarea1"."Account_Category"),
REPORT_AGGREGATE("subjectarea2"."budgetamount"-("subjectarea1"."Debit"-"subjectarea1"."Credit") BY "subjectarea1"."Account_Category")
FROM (SELECT "gl:gl detail"."project"."SIHB:PROJECT_INDIRECT_RATE" Indirect,
"gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" GLaccount,
CASE WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" IN ('45010','50010') THEN 'Direct Revenue' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" IN ('45020','50020') THEN 'Indirect Revenue' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" ='70010' THEN 'Salaries' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" IN ('70020','70030','70040','70045','70050','70055','70060','70070','70080','70090','70100','70110') THEN 'Fringe' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" BETWEEN '70120' AND '89999' THEN 'Other Direct (AP Expenses)' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" ='90000' THEN 'Indirect Expense' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" IN ('40010','40020','40030','40040','40050','41010','41020','41030','41040','41050','41060','43000','43010','44010','45030','45070','50030','51010','51015','51020','51030','51033','51035-001','51035-002','51035-003','51035-004','51035-005','51035-006','51035-007','51035-008','51035-009','51035-010','51035-011','51035-012','51035-013','51035-014','51035-015','51035-016','51035-017','51035-018','51035-019','51035-020','51035-021','51035-022','51035-023','51035-024','51035-025','51035-026','51035-060','51035-062','51040','51050','51060','51070','51075','52010','52020','53010','53020','53030','54010','54020','54030','58010','58020','59999') THEN 'Other Revenue Accounts' WHEN "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" ='98010' THEN 'Capital Asset (Grant)' ELSE "gl:GL Detail"."General ledger detail Attributes"."ACCOUNTNO" END Account_Category,
"gl:gl detail"."Project"."name" ProjectName,
"gl:gl detail"."project"."poamount" PurchaseOrderAmount,
"gl:gl detail"."Project"."projectid" ProjectID,
"gl:gl detail"."project"."BEGINDATE " BeginDate,
"gl:gl detail"."General ledger detail Measures"."CREDITAMOUNT" Credit,
"gl:gl detail"."General ledger detail Measures"."DEBITAMOUNT" Debit,
"gl:gl detail"."project"."ENDDATE" EndDate
FROM "gl:GL detail") subjectarea1 left outer join (SELECT "gl:GL Budget"."GL budget Attributes"."BUDGETID" BudgetID,
"gl:GL Budget"."Project"."Locationname" Location,
"gl:GL Budget"."GL budget Measures"."AMOUNT" budgetamount,
"gl:GL Budget"."GL budget Attributes"."ACCT_NO" BudgetAcount,
CASE WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" IN ('45010','50010') THEN 'Direct Revenue' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" IN ('45020','50020') THEN 'Indirect Revenue' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" ='70010' THEN 'Salaries' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" IN ('70020','70030','70040','70045','70050','70055','70060','70070','70080','70090','70100','70110') THEN 'Fringe' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" BETWEEN '70120' AND '89999' THEN 'Other Direct (AP Expenses)' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" ='90000' THEN 'Indirect Expense' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" IN ('40010','40020','40030','40040','40050','41010','41020','41030','41040','41050','41060','43000','43010','44010','45030','45070','50030','51010','51015','51020','51030','51033','51035-001','51035-002','51035-003','51035-004','51035-005','51035-006','51035-007','51035-008','51035-009','51035-010','51035-011','51035-012','51035-013','51035-014','51035-015','51035-016','51035-017','51035-018','51035-019','51035-020','51035-021','51035-022','51035-023','51035-024','51035-025','51035-026','51035-060','51035-062','51040','51050','51060','51070','51075','52010','52020','53010','53020','53030','54010','54020','54030','58010','58020','59999') THEN 'Other Revenue Accounts' WHEN "gl:GL Budget"."GL budget Attributes"."ACCT_NO" ='98010' THEN 'Capital Asset (Grant)' ELSE "gl:GL Budget"."GL budget Attributes"."ACCT_NO" END Account_Category2,
"gl:GL Budget"."Project"."PROJECTID" ProjectIDD FROM "gl:GL Budget") subjectarea2 ON (subjectarea1.ProjectID = subjectarea2.ProjectIDD) AND (subjectarea1.GLaccount = subjectarea2.BudgetAcount)
WHERE
(subjectarea2.BudgetID = 'Budget') AND (subjectarea1.ProjectID = '131-20') AND (subjectarea1.GLaccount BETWEEN '70010' AND '90000') AND (subjectarea2.BudgetAcount BETWEEN '70010' AND '90000')
ORDER BY saw_0, saw_1, saw_2, saw_3, saw_4, saw_5, saw_6, saw_7, saw_9, saw_12
Anyone know what im doing wrong here?
I tried to create an aggregate within an aggregate, but found that is not possible with oracle fusion middleware. Also, I understand that this is probably a simple problem for many, but I've gotten desperate. Any help is much appreciated!