如何计算出勤率

时间:2015-05-30 12:58:37

标签: mysql

我正在计算每个学生的总出勤率。我有两张单独的桌子,我将学生的姓名和身份证保存在学生桌上,并将出勤和身份证保留在考勤桌上。在考勤表上,每个学生有30行,1和0.我想列出每个学生的出勤率(总共0)与列出的名称。 sql应该是什么样的?谢谢你的帮助

$sql="SELECT * FROM students LEFT JOIN attendance ON students.KategoriID = attendance .KategoriID where WHERE attendance =0 "; 
$sonuc = mysql_query ($sql) ; 
while($satir=mysql_fetch_array($sonuc)) { 

1 个答案:

答案 0 :(得分:0)

<强> QUERY:

SELECT student.*, count(attendance.attendance) AS absent FROM student 
LEFT JOIN attendance ON student.KategoriID =attendance.KategoriID  
AND attendance.attendance=0 GROUP BY attendance.KategoriID ORDER BY    
student.KategoriID;

尝试此查询。

检查SQL FIDDLE