Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Symfony Query Builder: How to count rows AFTER group by?

$
0
0

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.


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>