mysql查询如何汇总出勤状态值

时间:2013-06-05 12:29:40

标签: mysql

我是mysql的新手。在上表中,我必须SUM attendance_status(column),具体取决于日期

01/05/2013 att_stat=0
01/05/2013 att_stat=1
02/05/2013 att_stat=0
02/05/2013 att_stat=1

当我插入第四个不能正常工作时,只有3个记录时,它的效果非常好

SELECT SUM(Attendance_Status) as total FROM student_attendance1 Where Attendance_Status='1' and Date= '"+datevalue+"'";'

1 个答案:

答案 0 :(得分:3)

基本上你很近,只需要放GROUP BY

SELECT
  SUM(Attendance_Status) AS total
FROM student_attendance1
WHERE Attendance_Status = '1'
    AND DATE = '"+datevalue+"'"
GROUP BY DATE