使用Codeigniter Active记录重写MySQL查询

时间:2012-12-14 12:38:09

标签: mysql codeigniter activerecord codeigniter-2

我不久前启动了CodeIgniter。有人可以告诉我如何重写这个查询

SELECT question.timestamp AS question_time, reply.timestamp AS reply_time, 
(SELECT DATEDIFF(reply_time, question_time)) AS time_used_to_reply 
FROM question JOIN reply ON question.id = reply.question_id WHERE question.company_id=someid

使用activerecord

此外,任何快速了解activerecord的教程都将非常感激。感谢

1 个答案:

答案 0 :(得分:3)

经过多次研究,我最终编写了自己的活动记录脚本。

$this->db->select(array('DATEDIFF(reply.timestamp, question.timestamp)'))
    ->from('question')
    ->join('reply', 'question.id = reply.question_id')
    ->where('question.company_id', $company_id);

由于