我正在尝试按字段(年份)对我的实体进行分组并对其进行计数.
码:
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计数,因为它给出了一个错误,并且
我不知道用什么作为addOrderby(???,’DESC’)值?