简体   繁体   English

使用Codeigniter Active记录重写MySQL查询

[英]Rewrite MySQL query using Codeigniter Active record

I have started CodeIgniter not long ago. 我不久前已经启动CodeIgniter。 Can some tell me how to rewrite this query 有人可以告诉我如何重写此查询

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

using the activerecord 使用活动记录

Also any tutorial to quickly understand activerecord would be very appreciated. 此外,任何快速理解activerecord的教程都将不胜感激。 Thanks 谢谢

After many researches, I ended up writing my own active record script. 经过大量研究,我最终编写了自己的活动记录脚本。

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

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM