Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
ZF2 集計
$sm = $this->getServiceLocator();
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$sql = new \Zend\Db\Sql\Sql($adapter);
$select = $sql->select();
'latest_release' => new \Zend\Db\Sql\Predicate\Expression('MAX(album.release_date)')
'MAX(album.release_date) >= ?' => date('Y-m-d', strtotime('-1 year'))
//echo $select->getSqlString($adapter->getPlatform());
$statement = $sql->prepareStatementForSqlObject($select);
$resultSet = $statement->execute();
//SELECT `album`.`artist` AS `artist`, MAX(album.release_date) AS `latest_release` FROM `album` GROUP BY `album`.`artist` HAVING MAX(album.release_date) >= '2013-03-09'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment