我想执行这样的 SQL 查询:
SELECT a.*, (time - (SELECT time FROM activity
WHERE time < a.time ORDER BY time DESC LIMIT 1) ) AS czas
FROM activity a WHERE 1 LIMIT 6000
我准备了以下代码 ZF:
$activity = new Application_Model_DbTable_Activity();
$subSql = $activity->select()
//->setIntegrityCheck(false)
->from(array('aw' => 'activity'), array('time'))
->where('time < a.time', '')
->order('time DESC')
->limit(1);
// main query
$sql = $activity->select()
//->setIntegrityCheck(false)
->from(array('a' => 'activity'), array('a.*', 'czas' => new Zend_Db_Expr('(a.time - (' . $subSql . '))')))
->where(1)
->limit(6000);
$this->rows = $bugs->fetchAll($sql);
不幸的是,这个解决方案不起作用。我应该改进什么?
对不起我的英语不好