我想检查r.is_show_map = 1,如果为true,则返回r.lat,否则返回null
这是代码
$this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat', false);
问题是它导致了语法错误
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AN' at line 1
SELECT r.*, IF(r.is_show_map = 1, r.lat, null) as r.lat FROM (`request` as r) WHERE `r`.`adv_type` != 0 AND `r`.`is_delete` = 0 AND NOW() <= DATE_ADD(r.create_date, INTERVAL 15 DAY)
如何解决?感谢
答案 0 :(得分:1)
试试这个:
$this->db->select('r.*, IF(r.is_show_map = 1, r.lat, null) as lat', false);