SQL语句的问题包括WHERE,AND,OR子句codeigniter

时间:2013-11-26 22:57:14

标签: php mysql sql codeigniter

我无法弄清楚如何修复此查询。

这是我的CodeIgniter代码

    return $this->db
        ->select('vehVin, vehMake, vehModel, seller, dealership, buyer, logistics.warehouseName, transportDate, car_tracking.keys, car_tracking.window')
        ->where('transportDate <', $yesterday)
        ->where('(car_tracking.keys', "'0'", FALSE)
        ->or_where("car_tracking.stickers = '0')", NULL, FALSE)
        ->join('logistics',  'logistics.stockid = vehicles.stockid')
        ->join('car_tracking',  'car_tracking.stockid = logistics.stockid')
        ->get('vehicles')
        ->result();

这就是我得到的错误

Unknown column 'car_tracking.stickers' in 'where clause'

`SELECT `vehVin`, `vehMake`, `vehModel`, `seller`, `dealership`, `buyer`, `logistics`.`warehouseName`, `transportDate`, `car_tracking`.`keys`, `car_tracking`.`window`
 FROM (`vehicles`) 
 JOIN `logistics` ON `logistics`.`stockid` = `vehicles`.`stockid` 
 JOIN `car_tracking` ON `car_tracking`.`stockid` = `logistics`.`stockid` 
 WHERE `transportDate` < '2013-11-25' 
 AND (car_tracking.keys = '0' OR car_tracking.stickers = '0')`

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

确保car_tracking.stickers存在。 我还会考虑将sql查询原始化。因为codeigniter的查询构建器有很多问题。它们一起使用时无法处理大多数查询条件。