我正在做这样的sql进入zend框架的sql模式.
SELECT jobs . *,c.id AS cid,c.name AS name,c.companyImage AS companyImage,c.logo AS logo,count(app.userId) AS t_app,app.applyStatus AS applyStatus,app.userId AS appUserId FROM jobs LEFT JOIN companies AS c ON jobs.companyName = c.id LEFT JOIN applicants AS app ON jobs.id = app.jobId AND app.applyStatus = 1 WHERE jobs.ownerId = 16 AND jobs.draftId != 0 GROUP BY jobs.id ORDER BY jobs.id DESC LIMIT 3
$adapter = $this->tableGateway->getAdapter(); $sql = new sql($adapter); $select = $sql->select(); $select->from('jobs') ->join(array('c' => 'companies'),'jobs.companyName = c.id',array('cid' => 'id','name','companyImage','logo'),'left') ->join(array('app' => 'applicants'),' jobs.id = app.jobId AND app.applyStatus = 1',array('t_app' => new Expression('count(app.userId)'),'applyStatus','appUserId' => 'userId'),'left') ->where("jobs.ownerId ={$userId} AND jobs.draftId != 0") ->group('jobs.id') ->order('jobs.id DESC') ->limit(3); $statement = $sql->getsqlStringForsqlObject($select); $results = $adapter->query($statement,$adapter::QUERY_MODE_EXECUTE);
但不能正常工作,并发出如下的信息.
sqlSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'on clause'