sql - avg in query - mysql -


i have query

  select salary     worker w     join single_user u on u.users_id_user = w.single_user_users_id_user     join university_has_single_user on us.single_user_users_id_user = u.users_id_user     join course c on c.id_course = us.course_id_course     join formation_area fa on fa.id_formation_area = c.formation_area_id_formation_area    fa.area = "multimédia" group users_id_user 

...that gave output:

salary -------- 1400.00 800.00 

how can calculate avg of output? if add:

select round(avg (salary), 0)  

...the output again 1400.00 , 800.00, not avg (because group by).

use:

 select avg(distinct salary)    worker w    join single_user u on u.users_id_user = w.single_user_users_id_user    join university_has_single_user on us.single_user_users_id_user = u.users_id_user    join course c on c.id_course = us.course_id_course    join formation_area fa on fa.id_formation_area = c.formation_area_id_formation_area   fa.area = "multimédia" 

because salary column not wrapped in aggregate, per documentation, values see arbitrary (can't guaranteed 100% of time).

usually, you'd need derived table average of distinct values mysql's avg supports using distinct within it.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -