devxlogo

Averaging Columns of Information

Averaging Columns of Information

Question:
How do I get the average of three columns for each row of a table that has four columns of information?

Answer:
Let’s say you have a table called Test with four columns like this:

ID  Col1  Col2  Col31    10    20    20

This SELECT statement will return an average value for Col1, Col2 and Col3:

SELECT ((Col1+Col2+Col3)/3) AS ColAvg FROM TestColAvg                       ---------------------------- 16.666666(1 row(s) affected)

devx-admin

Share the Post: