我想在同一个选择语句中计算来自另一个表的记录数,我使用了 Left join
在选择语句中,我输入了 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)
但它只返回第一条记录,我可以解决这个问题吗?还是制作另一张 table ,让它只用于计数?
最佳答案
关于mysql - mysql 中的 count(*) 只返回一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10013593/