Last active
August 29, 2015 13:57
-
-
Save matstani/9445604 to your computer and use it in GitHub Desktop.
ZF2 集計
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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