我有一个带有“ matiere_id”的表“ note”,一个有字段名称的表“ matiere”。 我想按主题显示笔记的平均值。 我不知道如何用symfony4编写请求。
在我的存储库中:
public function findTest($id)
{
return $this -> createQueryBuilder ( 'n' )
->select("avg(n.note) as note_avg")
->where('n.idMatiere = :idMatiere')
->groupBy('n.idMatiere')
->setParameter('idMatiere', $id)
->getQuery();
}
在我的控件中:
$repo = $this->getDoctrine()->getRepository(Notation::class);
$tabMatieres = $this->getDoctrine()
->getRepository(Matiere::class)
->findBy([], ['nom' => 'ASC']);
$tests = $repo->findTest ();