Doctrine2在Group By之前订购 [英] Doctrine2 Order By before Group By
问题描述
通常,在SQL中,您将执行一个子选择解决方案,以便在GROUP BY减少之前订购结果数据集。选择:
SELECT * FROM(
SELECT * FROM a_table order by a_table.timestamp desc
)as table_tmp
group by userId
但是,我在DQL中难以实现。
任何人都可以指向正确的方向吗?
我的查询比这更复杂,我假设我通过'table_tmp'加入其他表,并在外部SELECT。
感谢。
恐怕DQL不能处理这样一个复杂的查询。但是Doctrine允许您编写一个自定义SQL查询并将其结果映射到对象中。
详细了解有关 Doctrine的文档页面。
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.
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.
这篇关于Doctrine2在Group By之前订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!