Users Pricing

forum

Home Forums How to Calculate an average number from three columns? – MindStick

How to Calculate an average number from three columns?

Samuel Fernandes 2000 25 May 2015

I am try to calculate an average number from three columns but only includes the column in the calculation if column is not null and is bigger than 0;

For example the average usually is

(column1+column2+column3)/3

But if column3 is null or 0 then it will be

(column1+column2+column3)/2 or (column1+column2)/2

I have this sol far but it is not complete. The average is wrong when one of the columns is 0

SELECT movie.title,
 movie.imdbrating,
 movie.metacritic,
 tomato.rating,
 ((imdbrating + metacritic + tomato.rating)/3) as average
FROM movie, tomato
WHERE movie.imdbid = tomato.imdbid

How can I implement this?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md