我正在尝试在数据库列中获取多个值的总和:
$goalsScored = $em->createQueryBuilder()
->select('sum(homeGoals)')
->from('LoginLoginBundle:Matchgame', 'mg')
->where("mg.homeTeam LIKE '" . $oneTeam->getTeamid()."'")
->getQuery()
->getSingleScalarResult();
我收到以下错误:
[Semantical Error] line 0, col 11 near 'homeGoals) FROM': Error: 'homeGoals' is not defined.
homeGoals在我的数据库中定义,为什么我会收到此错误?是因为某些值为空吗?
答案 0 :(得分:4)
您的选择中缺少表别名:
$goalsScored = $em->createQueryBuilder()
->select('sum(mg.homeGoals)')
->from('LoginLoginBundle:Matchgame', 'mg')
->where("mg.homeTeam LIKE '" . $oneTeam->getTeamid()."'")
->getQuery()
->getSingleScalarResult();