Subquery return me null value every time #5986

Open
opened 2026-01-22 15:24:03 +01:00 by admin · 0 comments
Owner

Originally created by @argoitz on GitHub (Jun 11, 2018).

Im using Symfony 3.0.9 with doctrine 2.5.
This is my composer require section:

"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.0.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"friendsofsymfony/user-bundle": "~2.0@dev",
"beberlei/DoctrineExtensions": "^1.0",
"symfony/var-dumper": "^3.4"
},

I'm trying to transform the SQL query into DQL subquery, but I'm getting a lot of problems.

SQL query:

,(SELECT (CASE WHEN count(_days) > 0 THEN 'yes' ELSE 'No' END) as available
FROM
(
  SELECT count(rtd.room_type_id) as _days
    FROM room_type_day as rtd
    WHERE rtd.date IN ('2018-06-20', '2018-06-21', '2018-06-22')
    GROUP BY rtd.room_type_id
    HAVING COUNT(rtd.room_type_id) = 3
) as sub) as availability

I try implementing like this, but i can't execute a subquery like "FROM( SELECT...".

Then, this is my DQL transformation:

,(SELECT (CASE WHEN count(rtd.roomType) > 0 THEN 'yes' ELSE 'no' END)
    FROM AppBundle:RoomTypeDayCancelationConditionAccommodation as RTDCCA2
    LEFT JOIN RTDCCA2.roomTypeDay as rtd
    WHERE rtd.date IN ('2018-06-20', '2018-06-21', '2018-06-22')
    GROUP BY rtd.roomType
    HAVING COUNT(rtd.roomType) = 3
) as disponible 

But now when I execute it, I get null value every time in response.

Please, can anyone help me converting SQL to DQL?
Thank you.

Originally created by @argoitz on GitHub (Jun 11, 2018). Im using Symfony 3.0.9 with doctrine 2.5. This is my composer require section: > "require": { > "php": ">=5.5.9", > "symfony/symfony": "3.0.*", > "doctrine/orm": "^2.5", > "doctrine/doctrine-bundle": "^1.6", > "doctrine/doctrine-cache-bundle": "^1.2", > "symfony/swiftmailer-bundle": "^2.3", > "symfony/monolog-bundle": "^2.8", > "sensio/distribution-bundle": "^5.0", > "sensio/framework-extra-bundle": "^3.0.2", > "incenteev/composer-parameter-handler": "^2.0", > "friendsofsymfony/user-bundle": "~2.0@dev", > "beberlei/DoctrineExtensions": "^1.0", > "symfony/var-dumper": "^3.4" > }, I'm trying to transform the SQL query into DQL subquery, but I'm getting a lot of problems. SQL query: ``` ,(SELECT (CASE WHEN count(_days) > 0 THEN 'yes' ELSE 'No' END) as available FROM ( SELECT count(rtd.room_type_id) as _days FROM room_type_day as rtd WHERE rtd.date IN ('2018-06-20', '2018-06-21', '2018-06-22') GROUP BY rtd.room_type_id HAVING COUNT(rtd.room_type_id) = 3 ) as sub) as availability ``` I try implementing like this, but i can't execute a subquery like "FROM( SELECT...". Then, this is my DQL transformation: ``` ,(SELECT (CASE WHEN count(rtd.roomType) > 0 THEN 'yes' ELSE 'no' END) FROM AppBundle:RoomTypeDayCancelationConditionAccommodation as RTDCCA2 LEFT JOIN RTDCCA2.roomTypeDay as rtd WHERE rtd.date IN ('2018-06-20', '2018-06-21', '2018-06-22') GROUP BY rtd.roomType HAVING COUNT(rtd.roomType) = 3 ) as disponible ``` But now when I execute it, I get null value every time in response. Please, can anyone help me converting SQL to DQL? Thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5986