Aggregate values in Doctrine_RawSql queries(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 查询中的聚合值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Doctrine_RawSql 查询中的聚合值
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01