I have the following Query
Right now this query pulls back 3 locations and summarizes it by Financial Class. I would like a 4th section that pulls is a summary of all 3 locations by Financial class.
I have tried a few things with cube with no luck. Any help or direction would be great.
Code:
SELECT
C.CPCODE "Group_Num"
, L.LOCNAME "Site_Name"
,FC.CDESC "FC_Desc"
,add_months(trunc(sysdate,'MONTH'),-12) "dtMonth -12"
,add_months(trunc(sysdate,'MONTH'),-11) "dtMonth -11"
,add_months(trunc(sysdate,'MONTH'),-10) "dtMonth -10"
,add_months(trunc(sysdate,'MONTH'),-9) "dtMonth -9"
,add_months(trunc(sysdate,'MONTH'),-8) "dtMonth -8"
,add_months(trunc(sysdate,'MONTH'),-7) "dtMonth -7"
,add_months(trunc(sysdate,'MONTH'),-6) "dtMonth -6"
,add_months(trunc(sysdate,'MONTH'),-5) "dtMonth -5"
,add_months(trunc(sysdate,'MONTH'),-4) "dtMonth -4"
,add_months(trunc(sysdate,'MONTH'),-3) "dtMonth -3"
,add_months(trunc(sysdate,'MONTH'),-2) "dtMonth -2"
,add_months(trunc(sysdate,'MONTH'),-1) "dtMonth -1"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-12)) THEN C.AMOUNT ELSE 0 END) "Month -12"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-11)) THEN C.AMOUNT ELSE 0 END) "Month -11"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-10)) THEN C.AMOUNT ELSE 0 END) "Month -10"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-9)) THEN C.AMOUNT ELSE 0 END) "Month -9"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-8)) THEN C.AMOUNT ELSE 0 END) "Month -8"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-7)) THEN C.AMOUNT ELSE 0 END) "Month -7"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-6)) THEN C.AMOUNT ELSE 0 END) "Month -6"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-5)) THEN C.AMOUNT ELSE 0 END) "Month -5"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-4)) THEN C.AMOUNT ELSE 0 END) "Month -4"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-3)) THEN C.AMOUNT ELSE 0 END) "Month -3"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-2)) THEN C.AMOUNT ELSE 0 END) "Month -2"
,SUM(CASE WHEN (trunc(to_date(C.POSTDATE,'j'),'MONTH')=add_months(trunc(sysdate,'MONTH'),-1)) THEN C.AMOUNT ELSE 0 END) "Month -1"
,Sum(C.AMOUNT) "Total_Pmts"
,add_months(trunc(sysdate,'MONTH'),-12) "Start_Date"
,(trunc(sysdate,'MONTH')-1) "End_Date"
FROM
MEDCHARGES C
LEFT JOIN MEDLOCATIONS L ON ((C.CPCODE = L.LOCCPCODE) AND (L.LOCCODE=C.DOCLOC))
LEFT JOIN FINANCIALCODES FC ON ((FC.FCCODE=C.CPCODE) AND (FC.CODES=C.BILLSTATUS))
WHERE
(C.CPCODE IN ('1','2','3'))
AND (C.TYPE='P')
AND (C.SPLITFLAG IS NULL)
AND (C.POSTDATE between to_Number(to_char(add_months(trunc(sysdate,'MONTH'),-12),'J')) and to_Number(to_char((trunc(sysdate,'MONTH')-1),'J')))
GROUP BY
C.CPCODE
, L.LOCNAME
,FC.CDESC
Right now this query pulls back 3 locations and summarizes it by Financial Class. I would like a 4th section that pulls is a summary of all 3 locations by Financial class.
I have tried a few things with cube with no luck. Any help or direction would be great.