How to ORDER BY CASE in Doctrine2 (Symfony2)

前端 未结 4 639
鱼传尺愫
鱼传尺愫 2020-12-28 14:45

I want to run this query by using Doctrine in Symfony 2.3. But it seems like Doctrine does not understand CASE statement. Can anyone help? Thank you in advance!



        
4条回答
  •  不思量自难忘°
    2020-12-28 15:38

    This one does the job for me when ordering by a relation-table or a local column if no relation exists:

    $doctrineQuery->add('orderBy', '(CASE WHEN COUNT(relation_table.uid)>0 THEN relation_table.price ELSE current_table.generic_price END) ASC');
    

提交回复
热议问题