Please consider these data:
Id        StateCode           PersonCode           Feature1
-----------------------------------------------------------
1             1                 2000                 10          
2             1                 2000                 13      
3             1                 3000                 20      
4             2                 2000                 1      
5             2                 2000                 13      
6             2                 4000                 10      
7             2                 4000                 11      
8             2                 5000                 10      
9             2                 5000                 1      
10            3                 2000                 10      
11            3                 3000                 9      
12            3                 3000                 1      
13            3                 3000                 4     
I want to get this result that come from distinct StateCode & PersonCode
Count       StateCode
  2            1
  3            2
  2            3
and I wrote this query:
SELECT COUNT(*) AS Count,aa.StateCode
FROM   
     (select distinct StateCode, PersonCode
      from @tbl) aa
GROUP BY aa.StateCode
How I can write this query with one query and group by?
and if possible how I can write this query with one LINQ query?
Thanks
 
     
     
     
     
    