我有這個內部連接查詢,我想要轉換成Laravel的流利。它是部分工作的事情。我能夠得到結果,但mysql支持的運算符如and
我發現很難將其應用於我的流利查詢。如何將這個內部連接mysql查詢轉換成Laravel的流利?
MySQL查詢:
SELECT students.surname as Name, subjects.name as Subject, grades.name as Class, terms.name as Term, score as Score
from scores
inner join students
on students.id = scores.student_id
and scores.student_id = 1
inner join subjects
on subjects.id = scores.subject_id
and scores.student_id = 1
inner join grades
on grades.id = scores.grade_id
and scores.student_id = 1
inner join terms
on terms.id = scores.term_id
and scores.student_id = 1
where scores.term_id = 1 or scores.term_id = 2 or scores.term_id = 3;
laravel查詢:
$scores = \DB::table('scores')
->join('students', 'students.id', '=', 'scores.student_id')
->join('subjects', 'subjects.id', '=', 'scores.subject_id')
->join('grades', 'grades.id', '=', 'scores.grade_id')
->join('terms', 'terms.id', '=', 'scores.term_id')
->select('students.surname', 'subjects.name', 'grades.name', 'terms.name', 'score')
->where('students.id', '=', '1', 'and', 'scores.term_id', '=', '1', 'or', 'scores.term_id', '=', '2', 'or', 'scores.term_id', '=', '3')
->get();
的問題我現在是在我的where子句。這似乎是和運算符正在忽略並返回不在結果集中的結果。
五四時期不應該在結果集,因爲它是長期4. 注意項1第1期,期限2是第二期並且術語3是第3階段