我想要这样的事情:
$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)'
)
);
答案 0 :(得分:1)
酷!
工作实例:
$res = Model::find('all', array(
'fields' => array(
'SUM(col1) AS col1_total',
'SUM(col2) AS col2_total'
)
);