如何计算score
列中得分小于50的行数?
$user = DB::table('users')
->leftJoin('rankings', 'rankings.user_id', '=', 'users.id')
->select('users.*', DB::raw("( (count(rankings.score) ) ) as `countBelow50` ")
答案 0 :(得分:0)
检查高级连接子句:https://laravel.com/docs/5.7/queries#joins
$user = DB::table('users')
->leftJoin('rankings', function($join) {
$join->on('rankings.user_id', '=', 'users.id')
->where('rankings.score','<','50');
})
->select('users.*', DB::raw("( (count(rankings.score) ) ) as `countBelow50` ")