Вот оригинальный запрос:
Код: Выделить всё
select
`id`,
`name`,
round( ( 1000 + ifnull( `temp1`.`rate`, 0 ) - ifnull( `temp2`.`rate`, 0 ) ) ) as `rating`,
ifnull( `temp1`.`count`, 0 ) + ifnull( `temp2`.`count`, 0 ) as `matches`
from `team`
left join (
select `team1_id`, sum( `rate` ) as `rate`, count( `team1_id` ) as `count`
from `match` group by `team1_id`
) as `temp1` on `id` = `temp1`.`team1_id`
left join (
select `team2_id`, sum( `rate` ) as `rate`, count( `team2_id` ) as `count`
from `match` group by `team2_id`
) as `temp2` on `id` = `temp2`.`team2_id`
group by `id`
having `matches` <> "0"
order by `rating` desc, `name` asc
Код: Выделить всё
echo GridView::widget( [
'filterModel' => null,
'dataProvider' => new ActiveDataProvider( [
'query' => Team::find()
->addGroupBy( 'id' )
->orderBy( [
'rating' => SORT_DESC,
'name' => SORT_ASC
] ),
'pagination' => [ 'pageSize' => 100 ]
] )
] );
Код: Выделить всё
$query = new Query();
echo GridView::widget( [
'filterModel' => null,
'dataProvider' => new ActiveDataProvider( [
'query' => $query->select( 'id, name' )
->from( '{{%team}}' )
->addGroupBy( 'id' )
->orderBy( [
'rating' => SORT_DESC,
'name' => SORT_ASC
] ),
'pagination' => [ 'pageSize' => 100 ]
] )
] );