Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ZF2 集計
<?php
$sm = $this->getServiceLocator();
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$sql = new \Zend\Db\Sql\Sql($adapter);
$select = $sql->select();
$select->from('album');
$select->columns(array(
'artist',
'latest_release' => new \Zend\Db\Sql\Predicate\Expression('MAX(album.release_date)')
));
$select->group(array(
'album.artist'
));
$select->having(array(
'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