Mysql COUNT(*) on multiple tables

后端 未结 5 711
我寻月下人不归
我寻月下人不归 2020-12-23 22:55

What\'s wrong with this query:

SELECT co.*, mod.COUNT(*) as moduleCount, vid.COUNT(*) as vidCount 
 FROM courses as co, modules as mod, videos as vid 
 WHERE         


        
5条回答
  •  生来不讨喜
    2020-12-23 23:43

    Shoot this. I did the job with some non-mysql code:

    function getAllWithStats($info='*',$order='',$id=0)
    {
        $courses=$this->getAll($info,$order,$id);
    
        foreach ($courses as $k=>$v)
        {
            $courses[$k]['modCount']=$this->getModuleCount($v['id']);
            $courses[$k]['vidCount']=$this->getVideoCount($v['id']);
        }
    
        return $courses;
    }
    

提交回复
热议问题