SUM函数在Lithium ORM中的多个列上

时间:2016-10-31 08:58:29

标签: orm lithium

我想要这样的事情:

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

预期生成的SQL:

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

我尝试了很多方法。 这有可能吗?

单个col的工作示例:

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

1 个答案:

答案 0 :(得分:1)

酷!
工作实例:

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