1

假设有类似的东西:

SELECT energy_produced, energy_consumed, timestamp1 AS timestamp FROM (
SELECT max(energy_produced) AS energy_produced, mid(timestamp, 1, 10) AS timestamp1 FROM tbl_energy
WHERE site_id = 1366 AND mid(timestamp, 1, 10) >= DATE_SUB(curdate(),INTERVAL 1 day)
group by mid(timestamp1, 1, 10)) AS e1
INNER JOIN (
SELECT max(energy_consumed) AS energy_consumed, mid(timestamp, 1, 10) AS timestamp2 FROM tbl_energy
WHERE site_id = 1366 AND mid(timestamp, 1, 10) >= DATE_SUB(curdate(),INTERVAL 1 day)
group by mid(timestamp2, 1, 10)) AS e2
ON e1.timestamp1 = e2.timestamp2

我可以把它塞进一个变量中,然后像 $db->fetchAll($select)->toArray 这样调用傻瓜吗?

4

1 回答 1

3

是的,您可以将 SQL 语句作为字符串传递给$db->fetchAll()方法。

您不需要调用toArray()结果,因为默认情况下结果已经作为数组返回。

该类Zend_Db_Table也有一个fetchAll()方法,但它不接受 SQL 字符串,而是返回一个Zend_Db_Table_Rowset对象。

于 2008-12-13T02:04:41.330 回答