Doctrine_RawSql 查询中的聚合值
是否可以在 Doctrine_RawSql 查询中使用聚合值?这是我正在尝试做的事情:
Is it possible to use aggregate values in Doctrine_RawSql query? Here's what I'm trying to do:
$q = new Doctrine_RawSql();
$q->select('{q.*}, AVG(a.value) AS avg');
$q->from('-- complex from clause');
$q->addComponent('q', 'Question');
但是,Doctrine 创建的 SQL 只保留表 question
中的列,并省略聚合值 avg
.
However, SQL created by Doctrine leaves only columns from table question
and omits aggregate value avg
.
推荐答案
我之前从未使用过Doctrine_RawSql,但是我使用这两种方法之一通过Doctrine 完成了原始SQL 查询:
I've never used Doctrine_RawSql before, but I have done raw SQL queries through Doctrine using either of these two methods:
Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAssoc("YOUR SQL QUERY HERE");
和
$doctrine = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$result = $doctrine->query('YOUR SQL QUERY HERE');
这两种方法似乎会使您的原始 SQL 保持不变.
It seems like these two methods would leave your original SQL intact.
我应该注意,我在 Symfony 1.4 应用程序的上下文中使用 Doctrine 1.2,但是 AFAIK,无论您使用什么其他框架,这都对您有用.
I should note that I'm using Doctrine 1.2 within the context of Symfony 1.4 applications, but AFAIK, this would work for you regardless of what other frameworks you may be using.
相关文章