【问题标题】:sql count with inner join带有内部连接的 sql 计数
【发布时间】:2012-04-12 06:53:00
【问题描述】:

我有一张缺勤表,该表存储了缺勤人员的学生证。

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

为此我的查询是

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

它工作正常,我如何找到性别明智的出席者/缺席者......性别列在学生表中,谁能给我一些想法,提前谢谢

【问题讨论】:

    标签: sql count inner-join


    【解决方案1】:

    只需将性别列添加到您的 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-15
      • 2013-10-26
      • 2014-09-01
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      相关资源
      最近更新 更多