如何与Zend Db分组

时间:2018-09-11 07:30:16

标签: zend-framework2 zend-db zend-db-select

我使用zend framework 2,并且想要创建此选择:

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

这是我使用的功能:

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;
}

我如何实现呢?

感谢帮助!

0 个答案:

没有答案