我正在努力学习使用非常适合使用的select对象,至少对于不太复杂的查询。是否有任何限制使用此而不是手动SQL查询?
我更愿意在我的应用程序中随处使用它,但实际上不知道如何将它用于更复杂的查询,例如:
SELECT yt.rowid, yt.concat, added_latest, yt.volume, (yt.risk*yt.volume)
FROM obsoletes.batches yt
INNER JOIN(
SELECT rowid, batch, concat, volume as latest_vol, MAX(added) AS added_latest
FROM obsoletes.batches
GROUP BY concat) ss
ON yt.added = ss.added_latest AND yt.batch = ss.batch
WHERE yt.concat = 'something'
GROUP BY yt.batch
这可能吗?如何?文档不是很好。我也可以用吗? WHERE x IN(...)与选择对象?
提前致谢!
答案 0 :(得分:2)
不确定,但是类似的东西:
$inner = $db->select ()
->from ('obsoletes.batches', array (
'rowid',
'batch',
'concat',
new Zend_Db_Expr ('volume AS latest_vol'),
new Zend_Db_Expr ('MAX(added) AS added_latest')
))
->group ('concat');
$query = $db->select ()
->from ('obsoletes.batches', array (
'rowid',
'concat',
'volume',
new Zend_Db_Expr ('risk*volume')
))
->joinInner ($inner, 'yt.added = added_latest AND yt.batch = ss.batch')
->where ('concat = ?', 'something')
->group ('batch');