如何优化此查询。这是可行的,但我想要一个最佳的解决方案。
$query = AppUser::leftJoin(DB::raw('(SELECT user_id,question_id,answer FROM onlinetherapy_onboarding where question_id =8 GROUP BY user_id) b'),
function ($join) {
$join->on('app_users.id', '=', 'b.user_id');
})
->leftJoin(DB::raw('(SELECT user_id,status as verification_status FROM confirmation_codes GROUP BY user_id) c'),
function ($join) {
$join->on('app_users.id', '=', 'c.user_id');
})
->where('status', '=', $user_status);
我希望获得最佳查询。