Cumulative DQL with Doctrine

后端 未结 2 1429
情歌与酒
情歌与酒 2021-01-15 18:54

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.

Here is how it lo

2条回答
  •  梦谈多话
    2021-01-15 19:21

    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.

提交回复
热议问题