我是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']`
答案 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();