Using a 'case when' in a Doctrine select statement

后端 未结 5 1213
终归单人心
终归单人心 2021-01-18 17:28

I have a select query I\'d like to perform with Doctrine:

 $resultset = Doctrine_Query::create()
    ->select(\"t.code, t.description, case when t.id_outc         


        
5条回答
  •  灰色年华
    2021-01-18 17:55

    As mentioned by adavea, Doctrine now has added support for CASE expressions. You can do something like

     $resultset = Doctrine_Query::create()
    ->select("t.code, t.description")
    ->addSelect("CASE WHEN(t.id_outcome = 1) THEN 1 ELSE 0 END as in_progress")
    ->from('LuOutcome t')
    ->orderBy('t.rank')
    ->fetchArray();
    

    Hope this might help someone, thanks!

提交回复
热议问题