The generated SQL seems correct, as well as the DQL. The limitation here is the DB layer (MySQL in this case, as far as I can see), being unable to reference `SELECT`-clause values inside the `SELECT` clause.
What you'd do is therefore duplicating the expression producing `total_days` inside the `CASE WHEN` expression Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 6 June 2016 at 22:48, Aleksandra Mihaylova <[email protected]> wrote: > I'm trying to convert very complex MySQL query to DQL. The main problem is > coming when I'm trying to use or compare the alias column with name > *total_days*, here is the example *DQL query*: > > > SELECT (1+1) AS total_days,(CASE WHEN (total_days = 1) THEN 1 ELSE 0 END) AS > test > FROM AppBundle:PeriodPrices > > the query is more complex, but I keep it simple here only for the testing > purposes! Here is the exception: > > An exception occurred while executing ' > SELECT (1 + 1) AS sclr0, > (CASE WHEN (sclr0 = 1) THEN 1 ELSE 0 END) AS sclr1 > FROM PeriodPrices p0_': > > SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sclr0' in 'field list' > > this is the converted DQL to SQL query by Symfony framework, as I can see > the alias field sclr0 is not visible in the CASE statement. > > Note, if I'm using IF STATEMENT the query is working: > > > SELECT (1+1) AS total_days, > IF( (SELECT total_days ) = 2, 1, 0) AS test > > *The result:* > > total_days test 2 1 > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
