How to use yii2 joinWith aggregation (count, sum) query
I know use with
query:
$customers = Customer::find()->with([
'country',
'orders' => function ($query) {
$query->andWhere(['status' => Order::STATUS_ACTIVE]);
},
])->all();
But, When I use count in with
query, The result didn't contains aggregation column, Like that:
$query = UserInviteRecord::find()
->alias('ui')
->with([
'userInfo',
'inviteOrder' => function ($query) {
$query->select(['invite_user_id', 'count(id) as total_count']);
$query->where(['status' => 1]);
$query->groupBy('invite_user_id');
}])
->where(['ui.type' => 0])
Result only contains invite_user_id
column.
replace select
query:
$query->select(['invite_user_id', 'count(id) as开发者_Go百科 total_count']);
精彩评论