1

我想计算我在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 :(

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

4

1 回答 1

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();
于 2018-07-05T07:19:19.367 回答