我正在尝试按字段(年份)对我的实体进行分组并对其进行计数。
代码:
public function countYear()
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('b.year, COUNT(b.id)')
->from('\My\Entity\Album', 'b')
->where('b.year IS NOT NULL')
->addOrderBy('sclr1', 'DESC')
->addGroupBy('b.year');
$query = $qb->getQuery();
die($query->getSQL());
$result = $query->execute();
//die(print_r($result));
return $result;
}
我似乎不能说COUNT(b.id) AS count
,因为它给出了一个错误,我不知道用什么作为addOrderby(???, 'DESC')
值?