Doctrine2 Order By before Group By

流过昼夜 提交于 2020-01-13 06:15:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7446762/doctrine2-order-by-before-group-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!