我想根据他们的班级和学年显示学生的详细信息,这是我用来实现相同目标的方法:
SELECT
a1.fk_stu_id,
b.stu_fname,
c.class_name,
d.section_code,
e.acad_year
FROM
tbl_stu_class a1
JOIN
tbl_stu_details b
ON
(b.pk_stu_id = a1.fk_stu_id),
list_class c
JOIN
tbl_stu_class a2
ON
c.pk_class_id = a2.fk_class_id,
list_sections d
JOIN
tbl_stu_class a3
ON
d.pk_section_id = a3.fk_section_id,
list_acad_years e
JOIN
tbl_stu_class a4
ON
e.pk_acad_year_id = a4.fk_year_id
WHERE
c.class_name = '10';
但这会返回每个学生的学年的叉积......这是上述查询的输出:
fk_stu_id stu_fname class_name section_code acad_year
1 sss 10 A 2019
2 Second 10 A 2019
1 sss 10 A 2017
2 Second 10 A 2017
预期结果:
fk_stu_id stu_fname class_name section_code acad_year
1 sss 10 A 2019
2 Second 10 B 2017
有人可以解释为什么会这样吗?我该如何解决这个问题?提前致谢。