在活动记录代码点火器中的SELCT中进行选择

时间:2018-07-05 06:31:32

标签: php codeigniter codeigniter-3 codeigniter-query-builder

我想计算时差 我已经尝试在mysql上进行查询和查询工作

SELECT  *, CONCAT_WS(" ", date1, hour1) AS rhour1,  CONCAT_WS(" ", date2, hour2) AS rhour2, (SELECT TIMEDIFF(rhour2,rhour1) AS diffhour) from TABLE1

然后我使用codeigniter查询生成器在活动记录中写:

$this->db->select('*, CONCAT_WS(" ", date1, hour1) AS rhour1,  CONCAT_WS(" ", date2, hour2) AS rhour2, (SELECT TIMEDIFF(rhour2,rhour1) AS diffhour)');
$this->db->from('table1');
$this->db->join('table2','table1.code_number = table2.code_number');    
$query = $this->db->get();

结果我无法获得值diffhour:(

我的代码活动记录有什么问题?

1 个答案:

答案 0 :(得分:1)

希望这对您有帮助:

注意:请确保您已将表名和所有列名都添加为table1.code_number

$this->db->select('*');
$this->db->select('CONCAT_WS(" ", date1, hour1) AS rhour1');
$this->db->select('CONCAT_WS(" ", date2, hour2) AS rhour2');
$this->db->select('TIMEDIFF(CONCAT_WS(" ", date2, hour2),CONCAT_WS(" ", date1, hour1)) AS diffhour');

$this->db->from('table1');
$this->db->join('table2','table1.code_number = table2.code_number');    
$query = $this->db->get();