Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Last active July 3, 2016 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdevilopers/5f3ec2a52333cbfa37480ce081ac6b7b to your computer and use it in GitHub Desktop.
Save webdevilopers/5f3ec2a52333cbfa37480ce081ac6b7b to your computer and use it in GitHub Desktop.
Doctrine DQL error with COUNT in CASE
<?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);
@webdevilopers
Copy link
Author

webdevilopers commented Jul 3, 2016

@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