Find the average of two combined columns in sql
By definition, AVG(col1) = SUM(col1)/COUNT(*)
and AVG(col2) = SUM(col2)/COUNT(*)
, therefore (SUM(col1)+SUM(col2))/COUNT(*)
= AVG(col1) + AVG(col2)
.
Also, the commutativity of addition gives us (SUM(col1)+SUM(col2))/COUNT(*) = SUM(col1+col2)/COUNT(*)
and hence AVG(col1+col2)
.
To use the avg function,
SELECT avg(col1 + col2)
FROM test
WHERE uid=5;
SQLFIDDLE DEMO