How to use count and 'order by count()' in

2019-09-05 22:32发布

I want to use ORDERBY COUNT() sentence in Doctrine.

select p.name,count(p.id) from UserBundle:User p Order By count(p.id)

But it says.

[Syntax Error] line 0, col 58: Error: Expected end of string, got '('

However, with the following code:

select p.name,count(p.id) from UserBundle:User p Order By p.name;

it works.

Is there something wrong with Order by count() on Doctrine? How can I use it?

1条回答
够拽才男人
2楼-- · 2019-09-05 23:05

I don't know doctrine, but when using databases you can usually do something like this:

select p.name, count(p.id) AS myCount from UserBundle:User p Order By myCount

I just did a quick search on Google and it should work in your case.

查看更多
登录 后发表回答