id1 id2 year State Gender
==== ====== ====== ===== =======
1 A 2008 ca M
1 B 2008 ca M
3 A 2009 ny F
3 A 2008 ny F
4 A 2009 tx F
This is the table i have, I need to find the total No of distinct Count in this table. I need to consider id1 and id2 to find the Unique Count. so the result of the count should be grouped according to the state. considering the above example.
i need to get the result as
ca - count : 2 and for ny it should be : 1 as 3 A is repeated twice.
the query i came up is that:
select state,gender,year,count(distinct id1,id2) from table1
group by state,gender,year
in this query i couldn't calculate a distinct count of id1,id2. how should i modify my query to get the desired result. any help would be appreciated.