Doctrine 2 SUM()等效助手? [英] Doctrine 2 SUM() equivalent helper?

查看:150
本文介绍了Doctrine 2 SUM()等效助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

奇怪的是,Doctrine2助手中没有SUM()等价物?有最大,最小,数...我是盲人吗?

Strange, there is no SUM() equivalent in Doctrine2 helpers? There is max, min, count... am i blind?

// Example - $qb->expr()->avg('u.age')
public function avg($x); // Returns Expr\Func

// Example - $qb->expr()->max('u.age')
public function max($x); // Returns Expr\Func

// Example - $qb->expr()->min('u.age')
public function min($x); // Returns Expr\Func

// Example - $qb->expr()->abs('u.currentBalance')
public function abs($x); // Returns Expr\Func

// Example - $qb->expr()->sqrt('u.currentBalance')
public function sqrt($x); // Returns Expr\Func

// Example - $qb->expr()->count('u.firstname')
public function count($x); // Returns Expr\Func


推荐答案

喜欢它。

Looks like it.

// Example - $qb->expr()->sum('u.id', '2') => u.id + 2
public function sum($x, $y); // Returns Expr\Math instance

http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html

http://www.doctrine-project.org/docs/orm/2.0/en/reference/query-builder.html

编辑

我错了。 OP显然不会失明:似乎没有一个 sum()帮助。

I'm wrong. The OP is not going blind apparently: there does not appear to be a sum() helper.

你可以仍然在QueryBuilder中使用sum,如下所示:

You can still use sum in QueryBuilder like so:

$qb->add('select', 'SUM(u.id)')
   ->add('from', 'User u')
...

这篇关于Doctrine 2 SUM()等效助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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