logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$9
How to use SQL functions like SUM and YEAR using Propel?

Using the old Symfony 1.0 syntax, could someone suggest how to use functions like YEAR, while still using Propel, or at least Creole?

SELECT YEAR(start_date) as YEAR from contracts ORDER BY start_date DESC

This question has been answered.

marshall | 04/29/10 at 5:27pm Edit


(9) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    04/29/10
    6:30pm
    Arturo Linares says:

    like this:

    c->clearSelectColumns(); 
    $c->addSelectColumn('SUM(' . TablePeer::COLUMN . ')');
    $c->addGroupByColumn(TablePeer::COLUMN);

  • avatar
    Last edited:
    04/29/10
    5:36pm
    marshall says:

    Thanks. And what if I also need TablePeer::COLUMN to be DISTINCT ?

  • avatar
    Last edited:
    04/29/10
    5:38pm
    marshall says:

    I call this with doSelectRS() yes?

  • avatar
    Last edited:
    04/29/10
    5:39pm
    Arturo Linares says:

    Like this :)

    $c->setDistinct(true); // or $c->addSelectModifier(Criteria::DISTINCT); 

  • avatar
    Last edited:
    04/29/10
    5:40pm
    Arturo Linares says:

    Yes, yo call it with doSelectRS()

  • avatar
    Last edited:
    04/29/10
    6:07pm
    marshall says:

    Thank you. One last follow-up! How do I set an alias, like "SUM(contract_value) AS total".

  • avatar
    Last edited:
    04/29/10
    6:11pm
    marshall says:

    I tried


    $c->addSelectColumn('SUM(' . TablePeer::COLUMN . ') AS total');

    which got me the correct SQL, yet when I try to fetch it:

    $results = CaoIssuePeer::doSelectRS($c);

    print_r($results);

    while ($results->next()) {
    echo $results->getString('total');
    }

    I get:

    [SQLException]
    Invalid resultset column: total

  • avatar
    Last edited:
    04/29/10
    6:16pm
    Arturo Linares says:

    You will have to retrieve it by the column number, like:

    echo $results->getString(1);

  • avatar
    Last edited:
    04/29/10
    6:29pm
    marshall says:

    Perfect, thanks.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.