Codeigniter ActiveRecord,选择CONCAT AS

时间:2014-04-03 08:51:16

标签: mysql sql codeigniter

我是CodeIgniter Active Record的新手

我需要帮助转换此SQL查询

SELECT w.PATIENT, 
CONCAT( 'Bed',' ',h.BED_NO ,' ', 'in' ,' ','Room',  h.ROOM_NO ) AS Location,
DATEDIFF(h.ALLOWED_DATE,w.WAITING_DATE) AS Duration  
FROM W w left outer join D d on w.Do=d.Do left outer join H h on w.P=h.P
WHERE w.patient=$_SESSION['user']`

1 个答案:

答案 0 :(得分:0)

使用Active Record即可

$this->db->select("w.PATIENT,
CONCAT( 'Bed',' ',h.BED_NO ,' ', 'in' ,' ','Room',  h.ROOM_NO )AS Location,
DATEDIFF(h.ALLOWED_DATE,w.WAITING_DATE) AS Duration
",FALSE);
$this->db->from('W w');
$this->db->join('D d ','w.Do=d.Do ','LEFT');
$this->db->join('H h',' w.P=h.P','LEFT');
$this->db->where('w.patient',$_SESSION['user']);
$result=$this->db->get();