Doctrine_RawSql查询中的聚合值

Jan*_*dek 4 php doctrine doctrine-1.2

是否可以在Doctrine_RawSql查询中使用聚合值?这是我正在尝试做的事情:

$q = new Doctrine_RawSql();
$q->select('{q.*}, AVG(a.value) AS avg');
$q->from('-- complex from clause');
$q->addComponent('q', 'Question');
Run Code Online (Sandbox Code Playgroud)

但是,Doctrine创建的SQL仅保留表中的列question并省略聚合值avg.

Ste*_*nte 6

我之前从未使用过Doctrine_RawSql,但我使用以下两种方法之一通过Doctrine进行了原始SQL查询:

Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAssoc("YOUR SQL QUERY HERE");
Run Code Online (Sandbox Code Playgroud)

$doctrine = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$result = $doctrine->query('YOUR SQL QUERY HERE');
Run Code Online (Sandbox Code Playgroud)

看起来这两种方法会使原始SQL保持不变.

我应该注意到我在Symfony 1.4应用程序的上下文中使用了Doctrine 1.2,但是AFAIK,无论你使用什么其他框架,这都适合你.