mysql group by z max wartością kolumny

  public function findLatestCreationDatesByOrderAndStatusesIds(
        OrderInterface $order,
        array $statusesIds
    ): array {
        $queryBuilder = $this->getQueryBuilder()
            ->select(
                \sprintf('IDENTITY(%s.status) as status', $this->getAlias()),
                \sprintf('max(%s.createdAt) as createdAt', $this->getAlias())
            )
            ->andWhere(\sprintf('%s.order = :order', $this->getAlias()))
            ->setParameter(
                'order',
                $order->getId(),
                PDO::PARAM_INT
            )
            ->andWhere(sprintf('%s.status IN (:statuses)', $this->getAlias()))
            ->setParameter(
                'statuses',
                $statusesIds,
                Connection::PARAM_INT_ARRAY
            );

        $queryBuilder->groupBy(sprintf('%s.status', $this->getAlias()));

        return $queryBuilder->getQuery()->getResult();
    }
Komentarze wyłączone