How to find average when instances are grouped or categorized on multiple columns?

There is a table 'Result' with following data:

ID   Title   Category  SubCategory  Value
1    Part-1  CatX      A            100
2    Part-1  CatX      B            0
3    Part-1  CatX      C            50
4    Part-1  CatY      A            100
5    Part-1  CatY      B            0
6    Part-1  CatY      C            100
7    Part-2  CatM      A            30
8    Part-2  CatM      B            10
9    Part-2  CatM      C            100
10   Part-2  CatN      A            50
11   Part-2  CatN      B            10
12   Part-2  CatN      C            80

And this is what I am trying to achieve:

Title   SubCategory   AvgValue
Part-1  A          100
Part-1  B          0
Part-1  C          75
Part-2  A          40
Part-2  B          10
Part-2  C          90

Each Title has 3 SubCategories and I need to display the Average Value of each SubCategory for every Title. Please Help. Answer can be a SQL server Query or Linq as I can get the Result table in a List/datatable.

#c# #sql #sql-server #entity-framework #linq

3 Likes2.50 GEEK