gpt4 book ai didi

mysql - Doctrine 2 不承认 FROM 子句上的 SELECT

转载 作者:可可西里 更新时间:2023-11-01 08:20:56 25 4
gpt4 key购买 nike

我有一个 SQL 查询,我想在 Doctrine2 中使用。

我的查询转到数据库,执行GROUP BY 用户状态和COUNT 每个状态的用户数。

然后我尝试加入一个表以COUNT 所有用户并为每个州计算一个百分比。

return $this->getEntityManager()
->createQuery("
SELECT COUNT(u.id) as total,
(100*(COUNT( u.id ) / total_users.total)) as percent
FROM UserBundle:User u,
(SELECT COUNT(*) as total
FROM UserBundle:User) as total_users
LEFT JOIN u.idUserEstado ue
GROUP BY u.idUserEstado")
->getResult();

问题是,当我运行 Doctrine2 查询时出现异常:

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

Doctrine 无法识别 FROM 子句中的 SELECT

最佳答案

在 from 子句上的选择不受学说 2 处理

在 doctrine 的 jira 上有一个已关闭(且未被接受)的功能请求:http://www.doctrine-project.org/jira/browse/DDC-2793

DQL is about querying objects. Supporting subselects in the FROM clause means that the DQL parser is not able to build the result set mapping anymore (as the fields returned by the subquery may not match the object anymore). This is why it cannot be supported (supporting it only for the case you run the query without the hydration is a no-go IMO as it would mean that the query parsing needs to be dependant of the execution mode).

关于mysql - Doctrine 2 不承认 FROM 子句上的 SELECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11137395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com