Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有内部联接的sql计数_Sql_Count_Inner Join - Fatal编程技术网

具有内部联接的sql计数

具有内部联接的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

我有一张缺席者的桌子,那张桌子存放着缺席者的学生

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

对此,我的疑问是

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