如何在 DQL 中 SELECT 具有 MAX(列值)的行?

How can I SELECT rows with MAX(Column value) in DQL?

我无法在我拥有的 symfony2 项目中获得此查询。

我的Table:

id  course  datetime    numOrden   
---|-----|------------|--------
1  | 1º  | 04/11/2016 | 1   
2  | 2º  | 04/11/2016 | 2
5  | 3º  | 04/11/2016 | 5  
3  | 4º  | 03/11/2016 | 4   
4  | 5º  | 03/11/2016 | 3 

我需要获取 "numOrden" 列中值为最大值的课程(在本例中为第 3 门课程)。为此,我在 Doctrine2 中使用了以下查询:

public function findCourse()
{
    return $this->getEntityManager()->createQuery(
    'SELECT c FROM BackendBundle:Curso c WHERE c.numOrden in (SELECT max(c.numOrden) FROM BackendBundle:Curso )')
    ->getResult();
}

    public function findCourse()
{
    return $this->getEntityManager()->createQuery(
    'SELECT c FROM Bundle:Course c WHERE c.numOrden=(SELECT max(c.numOrden) FROM Bundle:Course )')
    ->getResult();
}

但是显示如下错误:

[Syntax Error] line 0, col -1: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got end of string. (500 Internal Server Error)  

尝试在子选择中使用另一个别名:

    public function findCourse()
{
    return $this->getEntityManager()->createQuery(
    'SELECT c FROM Bundle:Course c WHERE c.numOrden=(SELECT max(co.numOrden) FROM Bundle:Course co )')
    ->getResult();
}

希望对您有所帮助