TB 1 : user_profile as ur-> id(PK),name (total 4k records all unique)
TB 2 : user_course_rel as ucr-> id,course_id,year_id,division,user_id(Fk)
TB 3 : students_attendance_lect as sal-> id,subject_id,date,student_id(Fk)
student_id(Fk) = user_id(Fk) = id(PK).
我想离开加入 TB1 并获取属于特定课程、年份、部门的所有学生的姓名,以及主题和日期的参与者,而不是应该是 132 条唯一记录的参与者。
运行以下查询后,我得到总数(4k 条记录)
select distinct(ur.id), ur.fname
from user_profile as ur
inner join user_course_rel as ucr
on ucr.user_id=ur.id
left join students_attendance_lect as sal
on sal.student_id=ucr.user_id
and ucr.course_id=1
and ucr.year_id=1
and ucr.division=3
and sal.subject_id=2
and sal.date='2013-01-21'