-1

我正在尝试通过 Doctrine 2.3 DQL 在 FROM 块中使用子查询。

每次我运行这个,得到以下错误

[Semantical Error] line 0, col 839 near '(SELECT ': Error: Class '(' is not defined.

这是我当前的 DQL 代码

$query = $this->getEntityManager()->createQuery('
SELECT 
        taS2.netDueDate,
        SUM(taS2.amountInThousands)                     AS SumAmountInThousands,
        SUM(taS2.netDAO1)                                       AS SumnetDAO1,
        SUM(taS2.netDAO2)                                               AS SumnetDAO2,
        SUM(taS2.netDAO3)                                           AS SumnetDAO3,
        SUM(taS2.netDAO4)                                               AS SumnetDAO4,
        SUM(taS2.netDueDate * taS2.amountInThousands)   AS SumNetDueDateInThousands,
        SUM(taS2.critical)  
FROM 
    (SELECT 
        ta.id,
        ta.documentDate,
        SUBSTRING(CONCAT(ta.netDueDate, \'\'), 9, 2) AS netDueDate,
        ta.discountRate, 
        ta.amountInThousands, 
        ta.netDAO1, 
        ta.netDAO2, 
        ta.netDAO3, 
        ta.netDAO4,
        ta.netDueDate,
        1 AS counter,
        CASE 
             WHEN (ta.clearingDate > ta.netDueDate) AND 
                     SUBSTRING(CONCAT(ta.clearingDate, \'\'), 6, 2) <> SUBSTRING(CONCAT(ta.netDueDate, \'\'), 6, 2)
             THEN ta.amountInThousands ELSE 0
        END AS critical
    FROM 
        AcmeBundle:Transaction ta
    WHERE
        ta.discountRate = 0) taS2

GROUP BY taS2.netDueDate
ORDER BY SUM(taS2.amountInThousands) DESC;
);

有人知道我如何正确地做到这一点吗?

4

1 回答 1

-2

您的查询看起来更像是SQL具有某些DQL功能的普通查询。您可以执行 SQL 查询$this->getEntityManager()->createNativeQuery();

另请阅读有关Doctrine2 子查询的信息

于 2013-08-29T08:33:39.380 回答