我想在DQL中获得一列的AVG,但我没有运气。
$qb = $this->em->getRepository($this->target)->createQueryBuilder('m');
$qb
->select($qb->expr()->avg('m.total_online as ACU'))
->where('m.server = :server')
->andWhere('m.time LIKE :time')
->setParameter('server', $server)
->setParameter('time',$date.'%');
$rs= $qb->getQuery()
->getResult();
,但它不会像我预期的那样给我带来的结果:
+--------+
| ACU |
+--------+
| 0.1429 |
+--------+
我的sql是:
SELECT AVG(Total_Online) as ACU FROM `monitor` WHERE time like '2016-12-01%' AND server='$x'
有人可以帮我吗?谢谢
我在这里得到答案:
$qb = $this->em->createQueryBuilder();
$rs = $qb
->select($qb->expr()->avg('m.total_online'))
->from($this->target,'m')
->where('m.server = :server')
->andWhere('m.time LIKE :time')
->setParameter('server', $server)
->setParameter('time',$date.'%')
->getQuery()
->getResult();
希望对某人有帮助。