Skip to content
Advertisement

Dynamic horizontal aggregate (AVG)

I have a table which contains 3 float(nullable) columns:

I need to get the average from these field (value1+value2+value3 / 3), but the divider is actually how many of these field that has value. So the expected result would be :

Anyone can help?

I’ve tried a solution according to this thread : Average of multiple columns

But didn’t seem to work.

I’ve also tried to handle this in C#, in which i use for loop and a counter to determine the divider, and then divide them. It actually works, but i prefer to handle this via query, because it took too much time when the records went over 3000 row(s).

My current query:

Thanks in advance.

Advertisement

Answer

You can try this below script-

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement