Skip to Main Content

DevOps, CI/CD and Automation

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!

sum over partition

853700May 6 2011 — edited May 7 2011
Hi,

I have a query like the following

select distinct ...... from tableA, tableB, tableC where .... order by .....

This will produce 12 rows.

If I take out the 'distinct' then it will produce 24 rows.

I want to change the query to the following.

select distinct ....,
sum (decode (tableA.column2, 'A', 1,0) over (partition by tableA.column1) count1,
....
from tableA, tableB, tabelC where .... order by ....

This will produce count1 = 24. But it should be 12 since I don't want to count the duplicate one.

I guess the above is counting every row (no distinct effect).

How will I change the query to reflect count1 for distinct row with my decode condiction?

Thanks for any tips in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 4 2011
Added on May 6 2011
1 comment
622 views