mysql - Calculate average using AVG function for multiple numbers -


i'm not sure used correct title, edit question if understand little bit more topic.

now tried test mysql's avg() function , tried query:

select avg(1,2,3) 

i expected give me 2 result. i've en error avg() intended receive column name single parameter. can not imagine need thing anywhere beyond artificial example believe understand sql language better if able execute such queries.

avg() aggregation function, operates on single oolumn of values (or single expression evaluated each row). doesn't take multiple arguments. want:

select (1 + 2 + 3) / 3 

contrast with:

select avg(t.n) (select 1 n union       select 2 union       select 3      ) t 

this summarizes 3 rows 1 row, calculating average.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -