我尝试在学说中获得 AVG 值,在我的 Repositoru 中我这样做:
public function getFotoSpecifica($idFoto) {
$q = $this->createQueryBuilder('f');
$q->leftJoin("f.foto_votata", 'v');
$q->where('f.id =:idFoto');
$q->andWhere('(f.foto_privata IS NULL OR f.foto_privata != 1)');
$q->andWhere('(f.foto_eliminata IS NULL OR f.foto_eliminata != 1)');
$q->expr()->avg('v.punteggio', true);
$q->setParameter('idFoto', $idFoto);
$dql = $q->getQuery();
$results = $dql->getArrayResult();
return $results;
}
但我没有找到任何值 avg,我看到了我所有的对象...我尝试在我的控制器中使用 createQuery 但我有很多错误,例如:错误:无效的路径表达式。必须是 StateFieldPathExpression。(这是外键)
mySql 查询是:
SELECT profilo_id, proprietario_id, round(AVG( punteggio ),2) as avg_rate, SUM(punteggio) as score, foto_id, count(*) as numero_votanti
FROM prof_voto_foto
WHERE foto_id = ?