2
我有一张桌子帐单,其中有3列 - partyname,billdate,billamount。还有另外一个表格会有专栏名称和分区。两者都与派对相关。我可以加入它们并在gridview中显示数据。我想是显示所有各方的数据如下使用yii2中的sum()和相关字段的组合
District Billdate Billamount
Kolkata 2016-03-02 20000
Malda 2016-03-02 30000
Jalpaiguri 2016-03-02 30000
的Billamount列的总和(金额)属于特定的地区。我读过Yii2 - getting sum of a column,Yii 2 ActiveDataProvider query with ->all() gives "Call to a member function andFilterWhere() on array" error,Yii2 Query does not return column sum,Yii2 - getting sum of a column。但无法实现。请帮忙。 我的搜索是
public function search($params)
{
$query = Bills::find();
$query->joinWith(['parties']);
//$command = Yii::$app->db->createCommand("SELECT sum(billamount) FROM bills");
//$sum = $command->queryScalar();
//echo $sum;
//$sum = $query->sum('billamount');
//echo $sum;
// $sum = (new \yii\db\Query())->from('bills');
// $sum = $sum->sum('billamount');
// echo $sum;
//$sum = $query->sum('billamount');
//echo $sum;
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);