Doctrine_RawSql 查询中的聚合值 [英] Aggregate values in Doctrine_RawSql queries

查看:22
本文介绍了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.

这篇关于Doctrine_RawSql 查询中的聚合值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆