Doctrine2 排序依据先于分组依据
我在实现子选择解决方案以在 GROUP BY 减少结果数据集之前对结果数据集进行排序时遇到问题。
通常,在 SQL 中,您会执行子选择:
SELECT * FROM (
SELECT * FROM a_table order by a_table.timestamp desc
) as table_tmp
group by userId
但是,我在 DQL 中实现此操作时遇到困难。 有人能指出我正确的方向吗?
我的查询比这更复杂,我假设我通过“table_tmp”和外部 SELECT 加入其他表。
谢谢。
I am having issues implementing a sub-select solution for ORDERING a resulting dataset before the GROUP BY reduces it.
Normally, in SQL you would do a sub-select:
SELECT * FROM (
SELECT * FROM a_table order by a_table.timestamp desc
) as table_tmp
group by userId
However, I am having difficulty implementing this in DQL.
Can anyone point me in the right direction please?
My query is more complex than this and I assume I JOIN other tables through 'table_tmp' and in the outer SELECT.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕 DQL 无法处理如此复杂的查询。但是 Doctrine 允许您编写自定义 SQL 查询并将其结果映射到对象中。
在 Doctrine 文档页面。
I'm afraid DQL isn't able to handle such a complex query. However Doctrine allows you to write a custom SQL query and map its results into objects.
Read more about native queries on Doctrine's documentation pages.