On the tail of my last question here, now I have one final problem I'm scratching my head about. I built a Case statement with two EXISTS subqueries. However, Oracle doesn't allow this CASE statement to be in the Group By because it has subqueries.
I actually can get this to work just fine if I wrap the case in a "MAX" statement, which allows me to not put it in the GROUP BY, but that presents other problems of it's own in my actual report using the data.
Is there anyway that I can use this CASE statement without wrapping it in an aggregate function?
Thanks again for any help!! ;-)
I actually can get this to work just fine if I wrap the case in a "MAX" statement, which allows me to not put it in the GROUP BY, but that presents other problems of it's own in my actual report using the data.
Is there anyway that I can use this CASE statement without wrapping it in an aggregate function?
Code:
SELECT
PLH300_PH_DIMSN.PH_NBR,
SUM(( MBR304_TM_PH_SUMM.ELG_CN )),
CASE
WHEN
(
SELECT
1
FROM
dual
WHERE
(EXISTS
(
SELECT *
FROM PLH300_PH_DIMSN p2,
MBR304_TM_PH_SUMM m2
WHERE
(
( p2.PH_NBR = PLH300_PH_DIMSN.PH_NBR )
AND ( p2.PH_DIMSN_KEY = m2.PH_DIMSN_KEY)
AND ( m2.DLY_TM_DIMSN_KEY= TME300_DLY_TM_DIMSN_Incurred.DLY_TM_DIMSN_KEY)
AND ( p2.PH_CAT_RMC_CD = '9 ')
AND ( p2.PH_CAT_MED_TYP_CD LIKE 'S%' )
AND ( p2.PH_CAT_MED_TYP_CD NOT IN ('SE ','SH ','S3A','S7A','SRA','STA','SXA','SYA') )
)
)
)
AND
(EXISTS
(
SELECT *
FROM PLH300_PH_DIMSN p1,
MBR304_TM_PH_SUMM m1
WHERE
(
( p1.PH_NBR = PLH300_PH_DIMSN.PH_NBR )
AND ( p1.PH_DIMSN_KEY = m1.PH_DIMSN_KEY)
AND ( m1.DLY_TM_DIMSN_KEY= TME300_DLY_TM_DIMSN_Incurred.DLY_TM_DIMSN_KEY)
AND ( p1.PH_CAT_RMC_CD = '9 ')
AND ( p1.PH_CAT_MED_TYP_CD NOT LIKE 'S%'
OR
p1.PH_CAT_MED_TYP_CD IN ('SE ','SH ','S3A','S7A','SRA','STA','SXA','SYA')
)
)
)
)
) = 1 Then 'Dual Network'
Else 'None'
END As MktStrat
FROM
TME300_DLY_TM_DIMSN,
TME300_DLY_TM_DIMSN TME300_DLY_TM_DIMSN_Incurred,
PLH300_PH_DIMSN,
MBR304_TM_PH_SUMM
WHERE
( MBR304_TM_PH_SUMM.PH_DIMSN_KEY=PLH300_PH_DIMSN.PH_DIMSN_KEY )
AND ( MBR304_TM_PH_SUMM.DLY_TM_DIMSN_KEY=TME300_DLY_TM_DIMSN_Incurred.DLY_TM_DIMSN_KEY )
AND ( TME300_DLY_TM_DIMSN_Incurred.DLY_TM_DIMSN_KEY=TME300_DLY_TM_DIMSN.DLY_TM_DIMSN_KEY )
AND (
PLH300_PH_DIMSN.PH_NBR = '00003022'
AND ( TME300_DLY_TM_DIMSN.CLNDR_MTHLY_DT ) = '2007/02'
)
GROUP BY
PLH300_PH_DIMSN.PH_NBR