If you do have nulls to deal with, then you could get in to messy case statements or something like this...
Code:
Select PKColumn, Avg(DataColumn)
From (
Select PKColumn, Col1 As DataColumn
From Table
Union All
Select PKColumn, Col1
From Table
Union All
Select PKColumn, Col1
From Table
) As AliasName
Group By AliasName.PKColumn
Select PKColumn, Avg(DataColumn)
From (
Select PKColumn, [!]Col1[/!] As DataColumn
From Table
Union All
Select PKColumn, [!]Col2[/!]
From Table
Union All
Select PKColumn, [!]Col3[/!]
From Table
) As AliasName
Group By AliasName.PKColumn
Basically, this will take the data across columns and make them rows, then apply the avg function.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.