gpt4 book ai didi

mysql - 尝试从 Symfony2 中的数据库获取列总和时出错

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:57 25 4
gpt4 key购买 nike

我正在尝试获取数据库列中多个值的总和:

                $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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com