adm_no
,subject_id
,exam_id
およびscore
フィールドのテーブルがあります。私はlaravel 5.4のupdateOrCreate
メソッドを使ってデータを挿入しました。重複を排除しながらクエリビルダーを使用してデータを出力する方法
私がデータを取得するとき、私はまだ重複を取得します。例えばユーザーが特定の科目の例2の学生の印を挿入し、同じ学生と科目についてそれを繰り返すと、すべての結果の最新行を取得する必要があります。ここで
は、私のクエリのサンプルです:
public function searchStudent()
{
$exam = Exam::all();
$term = Term::all();
$a = Input::get('adm_no');
$e = Input::get('exam_id');
$t = Input::get('term_id');
$y = Input::get('year');
$results = DB::table('results')
->select(DB::raw('DISTINCT(subject_id)'))
->where('adm_no', 'LIKE', '%' . $a . '%')
->where('exam_id','LIKE', '%' . $e . '%')
->where('term_id', 'LIKE', '%' . $t . '%')
->where('year', 'LIKE', '%' . $y . '%')
->orderBy('created_at', 'desc')
->get();
dd($results);
}
そのそれでも最新の値を選ぶません。 adm_no:1、subject_id:1の最初のレコードを言い、同じ生徒の35点と2点目を40点、40点を選んで35点を無視する方法を教えてください。 –
ああ、これはちょっと質問を変え、チェックアウトしようとする[この質問](http://stackoverflow.com/questions/1313120/retrieving-the-last-record-in-each-group) – Desh901