mysql中的count(*)只返回一条记录

KJA*_*KJA 1 mysql doctrine

我想计算同一个select语句中另一个表中有多少条记录,我使用了Left join,而在select语句中我把count(ag.*)看作 例:

$q = Doctrine_Query::create()
            ->select("a.answer_id,a.date_added , count(ag.content_id) AS agree_count")
            ->from('Answer a')
             ->leftJoin("a.Agree ag ON a.answer_id = ag.content_id AND ag.content_type = 'answer' ")
            ->where('a.question_id= ? ', $questionId)
Run Code Online (Sandbox Code Playgroud)

但它只返回第一张唱片,我可以修复吗?或制作另一张桌子并仅用于计数?

fan*_*nts 5

GROUP BY在查询中遗漏了一个.

这里有更多的信息.

如果没有GROUP BY子句,则只获取一行是正常的.