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!

Query to calculate the total count and subset count in the same query

713833Jul 24 2009 — edited Jul 28 2009
Hi,
Can someone help me with a query to get the following result?

Code ID Flag
A 1 P
A 2 Y
A 3 N
A 4 N
A 5 N
A 5 N
A 6 Y
A 6 Y

Result:

Code Total_Count Count_N
A 6 3

Total Count = Distinct(ID)
Count(N) = Number of Flag = "N", but need to do a distinct on the # of "N"s belonging to the same ID.
For ex,
A 5 N
A 5 N

Should be counted as (1).

I can write two independent queries to get these two counts, but can we do it in one single query?

Thanks for your time!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2009
Added on Jul 24 2009
4 comments
2,195 views