sum over partition
853700May 6 2011 — edited May 7 2011Hi,
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.