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}}