Cumulative DQL with Doctrine(Doctrine 的累积 DQL)
本文介绍了Doctrine 的累积 DQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难制定出合适的 DQL 来生成累积总和.我可以用普通的 SQL 来做,但是当涉及到 DQL 时,我无法掌握它.
Im having a hard time working out a proper DQL to generate cumulative sum. I can do it in plain SQL but when it comes to DQL i cant get hold of it.
这是它在 SQL 中的样子:
Here is how it looks in SQL:
<代码>
SELECT s.name, p.date_short, p.nettobuy,
(select sum(pp.nettobuy) as sum from price pp where pp.stock_id = p.stock_id and p.broker_id = pp.broker_id and pp.date_short <= p.date_short) as cumulative_sum
FROM price p
left join stock s on p.stock_id = s.id
group by p.stock_id, p.date_short
order by p.stock_id, p.date_short
谢谢
推荐答案
你好,我查看了 Doctrine 1.2 的文档,创建查询的方法是(注意别名):
Hey, I have check the documentation for Doctrine 1.2, and the way to create the query is (put attention on the alias):
$query = Doctrine_Query::create();
$query->addSelect('AVG(price) as price');
$query->addSelect('AVG(cost) as cost');
// as many addSelect() as you need
$query->from('my_table');
输出创建的 SQL 查询:
To output the SQL query created:
echo $query->getSqlQuery();
执行语句:
$product = $query->fetchOne();
访问检索到的数据是:
echo $product->getPrice();
echo $product->getCost();
阅读 按子句分组.
这篇关于Doctrine 的累积 DQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Doctrine 的累积 DQL


基础教程推荐
猜你喜欢
- 将变量从树枝传递给 js 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的foreach复选框POST 2021-01-01