-1

我想向所有学生展示,即使他们没有注册课程。我将如何修改此查询以显示 null 呢?

SELECT a.lastname,
       Count(c.credits) TotalCredits
FROM   students a
       INNER JOIN registration b
               ON a.studentid = b.studentid
       INNER JOIN courses c
               ON b.courseid = c.coursenumber
GROUP  BY a.studentid

查询由 John Woo 完成

4

1 回答 1

1

使用LEFT代替INNER

SELECT a.lastname,
       Count(c.credits) TotalCredits
FROM   students a
       LEFT JOIN registration b
              ON a.studentid = b.studentid
       LEFT JOIN courses c
              ON b.courseid = c.coursenumber
GROUP  BY a.studentid
于 2012-08-20T03:09:48.963 回答