我使用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;
}
我如何实现呢?
感谢帮助!