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


猜你喜欢
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Laravel 仓库 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01