Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Case Statement in Analytic Function SUM(n) OVER(PARTITION BY x)

DiscoUserDec 6 2006 — edited Dec 7 2006
Hi Guys,

I have the following SQL that doesn't seem to consider the When clause I am using in the case staement inside the analytic function(SUM). Could somebody let me know why? and suggest the solution?

Select SUM(Case When (A.Flag = 'B' and B.Status != 'C') Then (NVL(A.Amount_Cr, 0) - (NVL(A.Amount_Dr,0))) Else 0 End) OVER (PARTITION BY A.Period_Year) Annual_amount
, A.period_year
, B.status
, A.Flag
from A, B, C
where A.period_year = 2006
and C.Account = '301010'
--and B.STATUS != 'C'
--and A.Flag = 'B'
and A.Col_x = B.Col_x
and A.Col_y = C.Col_y

When I use this SQL, I get

Annual_Amount Period_Year Status Flag
----------------------- ------------------ --------- ------
5721017.5 --------- 2006 ---------- C -------- B
5721017.5 --------- 2006 ---------- O -------- B
5721017.5 --------- 2006 ---------- NULL ----- A

And when I put the conditions in the where clause, I get

Annual_Amount Period_Year Status Flag
----------------------- ------------------ --------- ------
5721017.5 ---------- 2006 ---------- O -------- B
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2007
Added on Dec 6 2006
27 comments
10,708 views