zend 框架选择对象和复杂连接

发布于 2025-01-05 23:18:43 字数 593 浏览 1 评论 0原文

我正在尝试学习使用 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 ( ... ) 与选择对象?

提前致谢!

I am trying to learn to use the select object which is really comfortable to use, at least with less complex queries. Is there any limitations using this instead of manual sql queries?

I would prefer to use it everywhere in my application but really don't know how to use it for more complex queries like this one:

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

Is this possible? And how? The documentation is not that great. Could I also use
WHERE x IN ( ... ) with the select object?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2025-01-12 23:18:43

不确定,但类似这样:

$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');

Not sure, but something like that:

$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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文