Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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