Ramin Firooz
Ramin Firooz

Reputation: 506

SUM function on multiple columns in Lithium ORM

I want something like this:

    $res = Model::find('all', array(
        'fields' => array(
            'SUM(col1)' => array(
                'alias' => 'col1_total',
                ),
            'SUM(col2)' => array(
                'alias' => 'col2_total',
                )
            )
        );

expected generated SQL:

    SELECT SUM(col1) AS col1_total, SUM(col2) AS col2_total 
    FROM `tbl` AS `Model` WHERE 1;

I tried many ways. is this possible?


a working example for a single col:

        $res = Model::find('all', array(
            'fields' => 'SUM(col1)'
            )
        );

Upvotes: 1

Views: 89

Answers (1)

Ramin Firooz
Ramin Firooz

Reputation: 506

Cool!
working example:

    $res = Model::find('all', array(
        'fields' => array(
            'SUM(col1) AS col1_total',
            'SUM(col2) AS col2_total'
            )
        );

Upvotes: 1

Related Questions