how to group by minute with doctrine query builder

744 views Asked by At

i want to do run that query with doctrine query builder

select * from stats group by MINUTE(date_time)

i have tried this query builder but thrown exception

[Semantical Error] line 0, col 50 near 'MINUTE(s.dateT': Error: Cannot group by undefined identification or result variable.

$queryBuilder =
        $entityManager->createQueryBuilder('Application\Entity\Stats');
    $queryBuilder->select('s')
        ->from('Application\Entity\Stats', 's');
    $queryBuilder->groupBy('MINUTE(dateTime)');

how do i group by with minute

1

There are 1 answers

0
Ivo On

The error shows you that you cannot group by result. If you can do it with row SQL just try this

$conn = $entityManager->getConnection();
$sql = "SELECT *, MINUTE(row.date) as m FROM `table` AS row GROUB BY m"
$query = $conn->prepare($sql);
$query->execute;
$query->fetchAll();