Yii2:为什么查询生成器不返回与SQL语句相同的结果?

[已更新]已修复

我有这样的 SQL语句

SELECT
    jea.subemployer_id,jea.employer_id,jea.job_id 
FROM
    job_employer_assoc AS jea
    INNER JOIN job AS j ON jea.job_id = j.job_id
    INNER JOIN subemployer AS s ON jea.subemployer_id = s.subemployer_id 
WHERE
    j.deleted = 0 
    AND j.klq = 0 
    AND j.STATUS = 0 
    AND s.FUNCTION IN ( 0,1 ) 
GROUP BY
    job_id

这是我的查询生成器

public function getallValidEmployerID()
    {
        $resultQuery = (new Query())
            ->select(['jea.subemployer_id','jea.employer_id','jea.job_id'])
            ->from(['job_employer_assoc AS jea'])
            ->innerJoin('job AS j',['jea.job_id' => 'j.job_id'])
            ->innerJoin('subemployer AS s',['jea.subemployer_id' => 's.subemployer_id'])
            ->where(['j.deleted' => 0])
            ->andWhere(['j.klq' => 0])
            ->andWhere(['j.status' => 0])
            ->andWhere(['s.function' => [0,1]])
            ->groupBy('job_id')
            ->all();
        return $resultQuery;
    }

为什么 SQL语句返回值 ,而 Query Builder返回空数组

gn666 回答:Yii2:为什么查询生成器不返回与SQL语句相同的结果?

我终于找出原因,['jea.job_id' => 'j.job_id']应该是'jea.job_id = j.job_id'

本文链接:https://www.f2er.com/2937335.html

大家都在问