P粉9086436112023-07-28 17:42:24
理想情況下,你應該要有類似這樣的結構:
students
id
name
tests
id
number
test_results
id
student_id
test_id
result
這樣你就可以在一個查詢中取得學生的所有結果。
SELECT test_results.result AS Result, students.name as Student, tests.number as Testnumber FROM test_results LEFT JOIN students ON students.id = test_results.student_id LEFT JOIN tests ON tests.id = test_results.test_id WHERE student_id = {{id}}