I have a query like this:
$qb = $this->createQueryBuilder('c') ->leftJoin('c.orders', 'o') ->innerJoin('c.club', 'cb') ->addselect('AVG(o.totalPrice) AS AverageValue') ->groupBy('c.id'); $qb->setMaxResults($limit)->setFirstResult($offset);
This pulls customers from the database, and calculates their average order value.
I need to make the list of customers paginated, but the counting query i have below counts the rows BEFORE the group by, giving me an inaccurate number of results to build the pagination:
$qb = $this->createQueryBuilder('c') ->select('COUNT(c.id) AS TotalCustomers') ->leftJoin('c.orders','o') ->innerJoin('c.club','cb') ->groupBy('c.id') ->setMaxResults(1);
I believe this needs a sub query to actually count the rows after the group by has happened but i'm not sure how to make the sub query with symfony query builder.