嵌套子查询中的错误在DQL中:类'('未定义 [英] Error in Nested SubQuery In DQL: Class '(' is not defined
问题描述
我有一个DQL,如下所示:
I have a DQL as like below:
SELECT at, count(at.id) FROM AccountTriple at JOIN at.property p JOIN at.account ac WHERE p.create_analytics = '1' GROUP BY at.property, at.value, ac.service
如你所见,它有三个连接。 at和ac都有大量的数据。为了优化它,我试图在连接之前将p.create_analytics ='1'检查移动到ac,给它一个较小的数据集加入。我正在尝试这样做:
As you can see, it has three joins. As 'at' and 'ac' both have large amount of data. In attempt to optimize it, I am trying to move the "p.create_analytics = '1'" checking before join to 'ac' to give it a smaller data set to join. I am trying to achieve something like this:
SELECT at, count(at.id) FROM ( SELECT at FROM AccountTriple at JOIN at.property p WHERE p.create_analytics = '1' ) JOIN at.account ac GROUP BY at.property, at.value, ac.service
但不知何故,我的语法不起作用。错误消息显示如下:
But somehow, my syntax isn't working. A error message is showing as below:
语义错误]行0,col 29 near'(SELECT at FROM':Error:Class' ('没有定义。
Semantical Error] line 0, col 29 near '( SELECT at FROM': Error: Class '(' is not defined.
在其他地方没有找到类似的例子,有没有人可以帮助修复这个DQL查询得到工作,提前感谢
Didn't find similar example anywhere else as well. Does anyone can help to fix this DQL query to get working? Thanks in advance.
推荐答案
使用 createSubquery()
函数在Doctrine中创建子查询,然后可以将子查询嵌套到主查询中。
Use the createSubquery()
function to create a subquery in Doctrine. You can then nest the subquery into your main query.
// build root query
$query = Doctrine_Query::create()
->from('Movie m')
->where('name = ?', 'Prometheus')
;
// build subquery
$subquery = $query->createSubquery()
->from('SeenMovie sm')
->where('m.name = sm.name')
;
// nest subquery and execute
$query->where('EXISTS (' . $subquery->getDql() . ')')->execute();
进一步阅读 >
创建任何复杂性的原则子查询的防弹模式
这篇关于嵌套子查询中的错误在DQL中:类'('未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!