【发布时间】:2017-07-25 14:34:08
【问题描述】:
我有一个结果表,其中有 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);
}
【问题讨论】:
标签: laravel