sql - Unable to use SELECT MAX CASE with doctrine -


i'm trying create dql request using max(case...) using postgresql

here's table exemple : (key values random)

[------table------] [type |key|value  ] [sweet|843|waffle ] [sweet|258|nutella] 

and here's i'd :

[type |dessert|sauce  ] [sweet|gaufre |nutella] 

and here's (working) sql i've done :

select      type,     max(case when key=843 valeur end) dessert,     max(case when key=258 valeur end) sauce     table group type 

but, can't convert sql query dql, here's tied (not working) :

$qb = $this->createquerybuilder('table') ->select('table.type') ->addselect('max(case when table.key=843 table.value end) dessert') ->addselect('max(case when table.key=258 table.value end) sauce') ->addgroupby('table.type') 

and here's error have :

 [syntax error] error: unexpected ')'  

i tried , without max, , dql generated correct. can help? lot guys!

the solution add else in case when clause:

$qb = $this->createquerybuilder('table') ->select('table.type') ->addselect('max(case when table.key=843 table.value else null end) dessert') ->addselect('max(case when table.key=258 table.value else null end) sauce') ->addgroupby('table.type') 

have nice day


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -