Zend DB 表摘要
我在将 SQL 查询转换为合适的 ORM 查询时遇到了一些困难
即使在 SQL 术语中查询也相当复杂,但我正在寻找将其整理为 ORM 查询的方法,因为我正在将我在 Flex 中生成了许多函数到 Zend 框架模型中,以供未来验证和 API 用途。
当前的平面SQL如下:
SELECT subcategory_id,
SUM(total) / (1+(YEAR(2011)*12+MONTH(1))-(YEAR(2011)*12+MONTH(12)))
AS monthly_average FROM aggr_subcategory WHERE user_id=1 AND month BETWEEN 01 AND 05
GROUP BY user_id, subcategory_id
我遇到的主要问题是SUM,我可以管理ORM中的GROUP和WHERE子句,但无法在DB表摘要中获取总和。
非常感谢任何帮助或指出正确方向。
I've hit a bit of a brick wall in converting an SQL Query into a suitable ORM Query
The query is pretty complex even in SQL Terms, But I am looking at ways of collating this into an ORM Query, as I'm converting a lot of functions I've produced in Flex into Zend Framework Models for future proofing and API Purposes.
The current flat SQL is as follows :
SELECT subcategory_id,
SUM(total) / (1+(YEAR(2011)*12+MONTH(1))-(YEAR(2011)*12+MONTH(12)))
AS monthly_average FROM aggr_subcategory WHERE user_id=1 AND month BETWEEN 01 AND 05
GROUP BY user_id, subcategory_id
The main issues I am having are the SUM, I can manage the GROUP and WHERE clauses in ORM, but cannot get the sum in the DB Table Abstract.
Any help or points in the right direction much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
结果是:
`
What about this:
Results in:
`
尽管 ORM 是很棒的工具,但它们不能(也不应该尝试)完全取代本机 sql。
您可以简单地通过以下方式执行您的sql:
Although ORMs are great tools, they cannot (and shouldn't try to) entirely replace native sql.
You can simply execute your sql by: