在Doctrine2中如何使用count和'order by count()' [英] How to use count and 'order by count()' in Doctrine2

查看:181
本文介绍了在Doctrine2中如何使用count和'order by count()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Doctrine中使用 ORDERBY COUNT()句子。

 从UserBundle中选择p.name,count(p.id):用户p按顺序排列(p.id)

但是它说。

  [语法错误]行0,col 58:错误:预期的字符串结束,得到'('

但是,使用以下代码:

 从UserBundle中选择p.name,count(p.id):用户p按p.name排序

它的工作。



有什么问题按count() / code> on Doctrine?如何使用?

解决方案

我不知道原则,但是当使用数据库你通常可以这样做:

  select p.name,count(p.id)AS myCount from UserBundle:User p订单由myCount 

我刚刚在Google上快速搜索,它应该适用于您的情况。 / p>

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?

解决方案

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.

这篇关于在Doctrine2中如何使用count和'order by count()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆