当我使用avg with count和sum时,无效使用组函数

时间:2018-01-10 20:30:23

标签: mysql sql average

我的查询有什么问题?

select p.name, p.photo, (
        SELECT AVG(count(ra.id_prof)/sum(ra.rate))
        FROM  rating ra
        WHERE  ra.id_prof = p.id) as rating  
from prof_table p, matier_prof mp, matiere m, niveau ni
where p.id=mp.id_prof and mp.id_matiere=m.id_mat and m.id_niv=ni.id_niv
having p.name like '%word%' or p.email like '%word%' or p.adresse like '%word%' or 
    p.biographie like '%word%' or m.matiere like '%word%' or ni.niveau like '%word%'

1 个答案:

答案 0 :(得分:0)

我已在您的请求的评论部分提到了您的问题。这可能就是你所追求的:从prof_table中选择,可以在其中一个列中找到该单词,或者存在匹配的matiere或niveau。

select 
  p.name, 
  p.photo, 
  (select avg(ra.rate) from rating ra where ra.id_prof = p.id) as rating  
from prof_table p
where p.name like '%word%' 
or p.email like '%word%' 
or p.adresse like '%word%' 
or p.biographie like '%word%' 
or p.id in
(
  select mp.id_prof 
  from matier_prof mp
  join matiere m on m.id_mat = mp.id_matiere
  left join niveau ni on ni.id_niv = m.id_niv
  where m.matiere like '%word%' or ni.niveau like '%word%'
);