问题描述
是否可以在 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.
这篇关于Doctrine_RawSql 查询中的聚合值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)