0

I use zend framework 2 and I want to create this select:

SELECT
MONTH(created_at) month, COUNT(*)
FROM
requests
GROUP BY
YEAR(created_at), MONTH(created_at)

This is my function I use:

public function statPerMonth() {
    $select = $this->tableGateway->getSql()->select();
    $select->where(array("created_at > '2017-07-01'"));
    $select->columns(array(
        'month' => new \Zend\Db\Sql\Expression('MONTH(created_at)'),
        'count' => new \Zend\Db\Sql\Expression('COUNT(*)')
    ));

    //$select->group(YEAR(created_at), MONTH(created_at));

    $row = $this->tableGateway->selectWith($select);
    return $row;
}

How can I realize it?

Thanks for help!

Mondy
  • 2,055
  • 4
  • 19
  • 29

0 Answers0