在phpmyadmin中,我可以运行以下查询:
SELECT TIMESTAMPDIFF(SECOND,first_load,last_load) AS uptime FROM table
但是我如何用codeignator的方式编写查询呢?这不管用:
$this->db->select('TIMESTAMPDIFF(SECOND,first_load,last_load) AS uptime')
真正的查询有点复杂,所以我只显示了一部分。这将是完整的查询(不起作用):
$this->db
->select('n.unique_id, n.name, b.impressions, b.clicks, TIMESTAMPDIFF(SECOND,first_load,last_load) AS uptime')
->from(self::$_table . ' AS b')
->join('sm_names AS n', 'n.id = b.name_id AND n.blocked = \'0\' AND n.unique_id != 11111111')
->where('b.last_load >', date('Y-m-d H:i:s', time() - (86400 * 2)))
->order_by($order, 'desc')
->limit($limit);
它会生成此错误消息:http://screencast.com/t/ZUYq58Rc6uA
谢谢。
最佳答案
尝试在括号关闭前在最后一次加载后的TIMESTAMPDIFF(SECOND,first_load,last_load)
中指定一个空格。