我试图在数据库列中获取多个值的总和:
$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是在我的数据库中定义的,那么为什么会出现此错误?是否因为某些值为空?
最佳答案
您选择的表别名缺失:
$goalsScored = $em->createQueryBuilder()
->select('sum(mg.homeGoals)')
->from('LoginLoginBundle:Matchgame', 'mg')
->where("mg.homeTeam LIKE '" . $oneTeam->getTeamid()."'")
->getQuery()
->getSingleScalarResult();
关于mysql - 尝试从Symfony2中的数据库获取列总和时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27158856/