0

查了很多,这里只好请教高手了……

表一(出席人数)

att_id att_date class_id student_id att_status
  1 07-11-2013 1 1
  2 07-11-2013 1 2 升
  3 07-11-2013 1 3
  4 07-11-2013 1 4
  5 08-11-2013 2 5
  6 08-11-2013 2 6
  7 08-11-2013 2 7
  8 08-11-2013 2 8
  9 09-11-2013 1 1 升
 10 09-11-2013 1 2
 11 09-11-2013 1 3 一个
 12 09-11-2013 1 4
 13 09-11-2013 2 5

其中 att_status P=Present,A=Absence,L=Leave。现在我想根据班级 id计算个别学生的出席、缺席和离开。

期望的结果

stu_id class_id 现在 缺勤 请假
  1 1 1 0 1
  2 1 1 0 1
  3 1 1 1 0
  4 1 2 0 0
  5 2 1 0 0
  6 2 1 0 0
  7 2 0 1 0
  8 2 1 0 0
4

1 回答 1

3
select student_id, 
       class_id, 
       sum(att_status='P') as present,
       sum(att_status='A') as absent,
       sum(att_status='L') as leave
from attendance
group by student_id, class_id
于 2013-11-10T07:41:02.327 回答