2012-04-12 64 views
1

我有一个缺席者的表,并且该表存储那些缺席者的studentids。与内部连接的SQL计数

从这个表格中我必须找到总的参加者和总缺席者,为此我刚加入了包含特定部分的最大容量的部分表格。

因为我这个查询是

select COUNT(Attendance.studentid) as Absentees 
     ,Sections.Max-count(studentid) as Presentees 
from Attendance 
inner join Students 
on students.StudentId=Attendance.StudentId 
inner join Sections 
on Sections.CourseId=students.CourseId 
group by Sections.Max 

它的做工精细,同样的道理我怎么能找到性别明智presentees /缺席......性别列是学生表,任何人都可以给我一些想法,在此先感谢

回答

5

只是性别栏添加到您的select ...列和group by,你会一行结束了对每个性别:

select COUNT(Attendance.studentid) as Absentees, 
     Sections.Max-count(studentid) as Presentees, 
     Students.Gender as Gender 
from Attendance 
inner join Students 
on Students.StudentId=Attendance.StudentId 
inner join Sections 
on Sections.CourseId=Students.CourseId 
group by Sections.Max, Students.Gender 
+0

现在工作正常,非常感谢tobyodavies – shanish 2012-04-12 07:06:29