具有内部联接的sql计数
我有一张缺席者的桌子,那张桌子存放着缺席者的学生 从这个表中,我必须找到总的出席者和总缺席者,为此,我加入了Sections表,该表包含特定部分的最大容量 对此,我的疑问是具有内部联接的sql计数,sql,count,inner-join,Sql,Count,Inner Join,我有一张缺席者的桌子,那张桌子存放着缺席者的学生 从这个表中,我必须找到总的出席者和总缺席者,为此,我加入了Sections表,该表包含特定部分的最大容量 对此,我的疑问是 select COUNT(Attendance.studentid) as Absentees ,Sections.Max-count(studentid) as Presentees from Attendance inner join Students on students.StudentId=Atte
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
它的工作很好,同样的方式我如何才能找到性别方面的演示者/缺席者……性别栏在学生表中,有人能告诉我一些想法吗,提前谢谢只需将性别栏添加到您的
选择…
栏和分组依据
,您将得到每个性别的一行:
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
只需将性别列添加到您的
选择…
列和分组依据
,您将得到每个性别的一行:
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