将 SQL 查询翻译成 Doctrine DQL(加入和分组依据)

Translate SQL query to Doctrine DQL (join and group by)

我需要将 SQL 查询转换为 Doctrine DQL。

SELECT g.id, g.round_id, g.score, g.prize_id
FROM game g
INNER JOIN (
    SELECT prize_id, MAX(score) score
    FROM game
    GROUP BY prize_id
) g2 
ON g.prize_id = g2.prize_id AND g.score = g2.score
ORDER BY prize_id DESC

怎么做?

我已经在 Doctrine DQL 中找到了如何做到这一点:

return $this->createQueryBuilder('g')
    ->leftJoin('App\Entity\Quizz\Game', 'g2', 'WITH', 'g.prize = g2.prize AND g.score < g2.score')
    ->andWhere('g2.prize IS NULL')
    ->getQuery()
    ->getArrayResult();