codeigniter,使用Case When for Where查询


codeigniter, Using Case When for Where Query

我有这个查询,我想让它在codeigniter查询形式工作,所以想知道它是否可能。

这是我想在Codeigniter中以Codeigniter自己的方式实现的查询。

    use zorkif_next;
SELECT 
    `osp_job_status_track`.`StatusID`,
    `osp_job_status_track`.`SubStatusID`,
    `osp_job_sub_status`.`CurrentStatus`
FROM
    (`osp_job_details`)
        LEFT JOIN
    `osp_job_status_track` ON `osp_job_status_track`.`JobID` = `osp_job_details`.`JobID`
        LEFT JOIN
    `osp_job_status` ON `osp_job_status`.`StatusID` = `osp_job_status_track`.`StatusID`
        LEFT JOIN
    `osp_job_sub_status` ON `osp_job_sub_status`.`SubStatusID` = `osp_job_status_track`.`SubStatusID`
        LEFT JOIN
    `hr_employee_details` ON `hr_employee_details`.`EmployeeID` = `osp_job_details`.`AssignToEmployeeID`
        LEFT JOIN
    `osp_job_type` ON `osp_job_type`.`JobTypeID` = `osp_job_details`.`JobtypeID`
WHERE
    -- `isDefault` = 1
       --    AND 
    CASE WHEN `osp_job_status`.`StatusID` = 2 
    THEN  `osp_job_sub_status`.`CurrentStatus` = 3
    ELSE `osp_job_status`.`StatusID` >= 2
    END ;
那么如何在 中实现这个查询呢?
$this->db->where($where);

? ?

这在CI中是不可能的。您需要编写自己的查询。请看一下这份文件。你可以在这里看到所有可用的方法。

'system'database'DB_active_rec.php