如何显示缺席或结果
请帮我解决此问题,谢谢
现在显示如此结果
________________________________________
Name TeacherNo Attendance
________________________________________
XYZ 993 5 Days Present
Abc 991 7 Days Present
123 955 2 Days Present
________________________________________
我想要这样
________________________________________________________________
Name TeacherNo Present Day Absent Days
_________________________________________________________________
XYZ 993 5 Days Present 3 Days Present
Abc 991 7 Days Present 0 Days Present
123 955 2 Days Present 4 Days Present
________________________________________________________________
这是代码
$result1 = mysql_query("select name ,id ,`teacherno` as teacherno, CONCAT(count(`teacherno`),' Present days') as Attendance
from tattendance
where `Attendance` = 'present' AND date BETWEEN '2013-04-01' AND '2013-04-07' group by `teacherno` order by attendance desc");
答案 0 :(得分:1)
您是否在寻找类似以下内容的信息:
SELECT name, teacherno,
CONCAT(COALESCE(SUM(CASE WHEN Attendance = 'present' THEN 1 END),0),' Present days') as Present,
CONCAT(COALESCE(SUM(CASE WHEN Attendance = 'absent' THEN 1 END),0),' Absent days') as Absent
FROM tattendance
GROUP BY teacherno
这会SUM
与CASE
一起使用,根据出勤列添加日期。我还包括COALESCE
以返回0而不是NULL
。