smc*_*hae 2 php mysql codeigniter codeigniter-3
我试图使用Codeigniter作为框架从数据库中获取数据.
我能够提出SQL查询以获得所需的结果,但由于我不熟悉Codeigniter DB语法,我遇到了麻烦.下面是我想要执行的查询.我怎么在PHP中这样做?
任何建议或建议将不胜感激.谢谢.
SELECT A.*, B.*
FROM
(SELECT A.*
FROM DriversInfo as A, InvoiceQueue as B
WHERE A.CreateTime = B.DriverCreateTime
AND B.Error <> 1
GROUP BY A.CreateTime
UNION
SELECT DISTINCT A.*
FROM DriversInfo as A, OrderInfo as B
WHERE A.CreateTime = B.DriverKey
AND B.Invoice <> '0') as A
LEFT JOIN DriversDoc as B
on A.CreateTime = B.DriverCreateTime
WHERE B.DriversLicense is null
OR B.CarRegistration is null
OR B.BizCertificate is null
OR B.Insurance is null;
Run Code Online (Sandbox Code Playgroud)
小智 5
试试这个:
$query=$this->db->query("SELECT A.*, B.* FROM (SELECT A.* FROM DriversInfo as A, InvoiceQueue as B WHERE A.CreateTime = B.DriverCreateTime AND B.Error <> 1 GROUP BY A.CreateTime UNION SELECT DISTINCT A.* FROM DriversInfo as A, OrderInfo as B WHERE A.CreateTime = B.DriverKey AND B.Invoice <> '0') as A LEFT JOIN DriversDoc as B on A.CreateTime = B.DriverCreateTime WHERE B.DriversLicense is null OR B.CarRegistration is null OR B.BizCertificate is null OR B.Insurance is null;");
Run Code Online (Sandbox Code Playgroud)