我想做的是在 codeigniter 中使用 sum,当我在浏览器中运行时出现错误,但我在 MYSQL 中查询,没有错误并且运行良好。
这是我的代码
$this->db->select('sum(if(`monitoring_type` = 1,1,0)) AS independent,sum(if(`monitoring_type` = 2,1,0)) AS buddy,count(*) AS TM, rate_info.qm_title');
$this->db->from('qm.recordings');
$this->db->join('qm.rate_info', 'recordings.record_id = rate_info.record_id');
$query = $this->db->get();
return $query->result();
我的错误
MySQL
最佳答案
将FALSE
作为第二个参数添加到
$this->db->select('你的查询', FALSE);
更新:
它从 codeigniter 默认为每个查询执行的选择语句中删除转义标识符(反引号)。所以
SELECT `column1`, `column2` FROM table
会变成
SELECT column1, column2 FROM table
关于php - 如何使用 Codeigniter Select with sum if?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18224026/