我想显示des = test1的分数总和;
$data=" ";
$student = Student::find(1)->student;
$scores = Score::where('school_id',$request->id)
->selectRaw('sum(score) as test, where des = Test1')
->groupBy('student_id','des')
->get();
if($scores)
{
$i=1;
foreach ($scores as $score)
{
$data .= '<tr><td>'.$i++.'</td>
<td>'.$score->student['name'].'</td>
<td>'.$score->test.'</td>
</tr>';
}
return Response($data);
}
答案 0 :(得分:0)
where子句不属于selectRaw语句。使用字符串时where子句也应保留在where des ='test1'