gpt4 book ai didi

php - 如何使用 Codeigniter Select with sum if?

转载 作者:行者123 更新时间:2023-11-29 04:23:02 27 4
gpt4 key购买 nike

我想做的是在 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();

我的错误 enter image description here

MySQL

enter image description here

最佳答案

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com