Last active
July 3, 2016 07:10
-
-
Save webdevilopers/5f3ec2a52333cbfa37480ce081ac6b7b to your computer and use it in GitHub Desktop.
Doctrine DQL error with COUNT in CASE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dql = "SELECT NEW | |
Acme\DomainModel\InspectionResult\ResultDetails( | |
e.id, e.date, | |
GroupConcat(DISTINCT e.comment), | |
CASE WHEN COUNT(bps_ok.id) = 0 THEN 1 ELSE COUNT(bps_ok.id) / COUNT(DISTINCT bps_ok.id) | |
) | |
FROM AppBundle\Entity\Bundle e | |
LEFT JOIN e.parttypeStateOk bps_ok | |
"; | |
$query = $this->_em->createQuery($dql); |
@KhorneHoly states in his answer:
It seems like using SUM
instead of COUNT
will work w/ DQL.
Unfortunately this will not work for my query:
If the rows of my IDs were e.g. 2 and 3 a COUNT would correctly return 2 (rows) but SUM would return 5.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Throws:
Error: Expected Doctrine\ORM\Query\Lexer::T_END, got ')'
Related: