public function actionScorechangwat() { $query = CmbisKpiResultHcode::find()->groupBy(['hcode'])->orderBy('avg(kpi_score) DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 25]]); $dataProvider->setSort(['attributes' => ['avgScore' => ['asc' => ['avg(kpi_score)' => SORT_ASC], 'desc' => ['avg(kpi_score)' => SORT_DESC], 'default' => SORT_ASC, 'label' => 'avg_score']]]); return $this->render('scorechangwat', ['dataProvider' => $dataProvider]); }
public function getAvgScore() { return $this->hasMany(CmbisKpiResultHcode::className(), ['hcode' => 'hcode'])->average('kpi_score'); }