使用带有count和sum的avg时,对group函数的使用无效

zzoitvuj  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(292)

我的查询有什么问题?

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%'
1l5u6lss

1l5u6lss1#

我已经在你的请求的评论部分提到了你的问题。这可能就是你想要的:从prof\ u表中选择,在prof\ u表中,单词可以在其中一列中找到,或者匹配的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%'
);

相关问题