Query to calculate the total count and subset count in the same query
713833Jul 24 2009 — edited Jul 28 2009Hi,
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!