SELECT 在活动记录 codeigniter 中的 SELECT 内
SELECT inside SELCT in active record codeigniter
我要计算时差
我已经尝试在 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 :(
我的代码活动记录有什么问题?
希望对您有所帮助:
注意:确保您已添加 table 名称和所有列名称,就像这样 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();
我要计算时差 我已经尝试在 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 :(
我的代码活动记录有什么问题?
希望对您有所帮助:
注意:确保您已添加 table 名称和所有列名称,就像这样 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();