2查询生成器abs函数

2查询生成器abs函数

本文介绍了Doctrine 2查询生成器abs函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此工作:

    $qb = $this->em->createQueryBuilder();

    $qb->select("abs(u.code) as code")
       ->from("User", "u")
       ->orderBy("code","ASC")
       ->getQuery()
       ->getArrayResult();

这不工作:

    $qb = $this->em->createQueryBuilder();

    $qb->select("u.code")
       ->from("User", "u")
       ->orderBy("abs(u.code)","ASC")
       ->getQuery()
       ->getArrayResult();

错误:

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

本机原则函数abs只能在选择部分的文件和
不按部就班。

The native doctrine function abs work only on a select part of statment anddon't work on order by part.

Obs:

2-)u.code是mysql上的varchar fild,需要是varchar(有时候是数字有些时候是字符串),我需要订购,就像一个数字的数字。

2-) u.code is a varchar fild on mysql and need to be varchar ( some times numeric and some times string), and i need to order then like a number in numeric case.

任何帮助?

推荐答案

解决atma感谢 abs() realy不直接在orderBy中工作,别名

Solved atma thank's abs() realy doesn't work directly in orderBy but as an alias.

soluction

soluction

SELECT field1,field2,abs(field3) AS abs_field3
FROM table
ORDER BY abs_field3 ASC

Obs:这是一个原则限制,不是mysql limita ,mysql suports abs直接按部分顺序。

Obs: It's a doctrine limitation, not a mysql limitation, mysql suports abs direct on order by part.

这篇关于Doctrine 2查询生成器abs函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:16