Doctrine 2 QueryBuilder でこのクエリを実行する方法:
SELECT AVG(x.distance) avg_distance FROM (SELECT r.* FROM 結果 r WHERE r.place_id = ? GROUP BY r.place_id ORDER BY r.id DESC LIMIT 100
私はこれを試します:
$dql = $qb
->select('r.*')
->from('CoreBundle:Result', 'r')
->where('r.place = :place')
->orderBy('r.id', 'DESC')
->setMaxResults(100)
->setParameter('place', $place)
->getDQL()
;
$result = $qb
->select('AVG(x.distance) avg_distance')
->from($dql, 'x')
->getQuery()
->getArrayResult();
しかし、動作しません
SELECT r.* FROM': Error: Class 'SELECT' is not defined.