Add in a > 48 in a where. If you don't want to include failed.
Jan 3, 2020
35
Level 1
Laravel Having clause issue.
This is my code below , I am trying to get sum all value where mark should be grater than $passMark(50) with specific username. Like username(jack_89) has 5 subjects and he gets 48 (failed mark) in one subject. I need if any student failed any or more than one subject count will not be happened.
$data = Exam::with('student')
->select('student_username', 'class', 'section', DB::raw('sum(mark) as total'), 'mark')
->where('section', $request->section)
->where('class', $request->sclass)
->where('exam_type', $request->exam_type)
->whereBetween('created_at', [
Carbon::now()->startOfYear(),
Carbon::now()->endOfYear(),
])
->groupBy('student_username', 'class')
->orderBy('total', 'desc')
->having('mark', '>', '$passMark')
->get();
return $data;
its always count all marks even student gets failed marks below 50 , thank you
Please or to participate in this conversation.