Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按多列值排序,带原则_Php_Sql_Symfony_Doctrine - Fatal编程技术网

Php 按多列值排序,带原则

Php 按多列值排序,带原则,php,sql,symfony,doctrine,Php,Sql,Symfony,Doctrine,我正试图找到一种方法,使用symfony2和条令,根据两列中的最小值对数据进行排序,类似于 $em=$this->getDoctrine()->getManager(); $test = $em->createQuery('select t from AcmeBundle:Test t where t.name is not null order by t.price1, t.price2')->getResult(); 问题是这样做首先按price1排序,然后按pri

我正试图找到一种方法,使用symfony2和条令,根据两列中的最小值对数据进行排序,类似于

$em=$this->getDoctrine()->getManager();
$test = $em->createQuery('select t from AcmeBundle:Test t where t.name is not null order by t.price1, t.price2')->getResult();
问题是这样做首先按
price1
排序,然后按
price2
排序


是否有一种方法可以使其按
price1
price2
中的最小值进行排序,组合而不是单独排序

选择并按COLLMNS的最小值订购
price
price1

$test = $em->createQuery('select b, CASE WHEN (price1 > price) THEN price ELSE price1 END as order_value from AcmeBundle:Test t where t.name is not null order by order_value')->getResult();

不完全是,我需要它按最小值排序,它可以是price1或price2,在哪一个中并不重要。感谢快速重播,但当我这样做时,我得到:[语法错误]:错误:预期已知函数,得到'IF'Ok,所以让我们尝试
CASE when
而不是
IF
。我更新了我的答案。这就成功了,唯一的问题是现在我得到的结果是一个多维数组,但实际上我需要的结果是一个对象数组。您可能知道有没有办法克服这种情况。请使用
getArrayResult()
而不是
getResult()
;)