Cumulative DQL with Doctrine

纵然是瞬间 提交于 2019-12-01 11:23:52

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');

To output the SQL query created:

echo $query->getSqlQuery();

To execute the statement:

$product = $query->fetchOne();

And to access the retrieved data is:

echo $product->getPrice();
echo $product->getCost();

Read the rest of the documentation at Group By Clauses.

You just specify the sum in your select part of the DQL:

$query = Doctrine_Query::create()
   ->select('sum(amount)')
   ->from('some_table');

Check out this page in the Doctrine documentation for more info.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!