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,
]);