2012-04-12 17 views
1

私は不在者のためのテーブルを持っており、そのテーブルは不在者の受験生を格納しています。内部結合の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は、各性別のために1行になってしまいます:

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

関連する問題