根据多个mysql表的左连接获取行计数

时间:2012-11-27 08:00:20

标签: php mysql left-join

我有一个问题:

SELECT students.rollno, students.name, COUNT( sp.paperid ) AS papers
FROM sps sp
LEFT JOIN students ON students.studentid = sp.studentid
LEFT JOIN str st ON st.studentid = sp.studentid
LEFT JOIN iars ir ON ir.paperid = sp.paperid
LEFT JOIN attndata at ON at.iarsid = ir.id
LEFT JOIN hedata he ON he.iarsid = ir.id
LEFT JOIN assigndata asg ON asg.iarsid = ir.id
WHERE sp.studentid = at.studentid
AND sp.studentid = asg.studentid
AND sp.studentid = he.studentid
AND students.course =4
AND st.semesterid =1
AND st.sessionid =12
AND students.status = 'Regular'
GROUP BY students.rollno

我有一个数据库,其中我有学生数据,即他们的论文,个人数据,出勤,作业,考试数据。我想计算在表格中有数据的论文数量,例如attndata,即出勤,assigndata即assignement和hedata,即考试和sps表有学生正在学习的文件,str表与学生学期有关。请帮助我们获得正确的论文数量。

感谢。

0 个答案:

没有答案