问题描述
我有2张桌子,但我想加入他们。怎么做
选择classSchedule。[classScheduleId]来自classSchedule
classScheduleId
------------
1000
1001
1002
选择classSchedule.classScheduleId,count(attendance.studentId)as attend where attendance.classScheduleId = classSchedule.classScheduleId group by(classSchedule.classScheduleId)
classScheduleId |参加
--------------------------
1001 | 2
但我期待的是
classScheduleId |参加
--------------------------
1000 | 0
1001 | 2
1002 | 0
我的尝试:
在这种情况下,我不知道如何做到这一点,我只是想找到一些例子来解决它,但直到现在我也不知道我要搜索的关键字
i have 2 table but I want join them together. how to do it
select classSchedule.[classScheduleId ] from classSchedule
classScheduleId
------------
1000
1001
1002
select classSchedule.classScheduleId ,count(attendance.studentId) as attend where attendance.classScheduleId=classSchedule.classScheduleId group by(classSchedule.classScheduleId )
classScheduleId | attend
--------------------------
1001 | 2
but what i expect is
classScheduleId | attend
--------------------------
1000 | 0
1001 | 2
1002 | 0
What I have tried:
In this case i dont know how to do so that i just try to find some example to solve it but until now i also dont know the keyword that i want to search
推荐答案
SELECT s.classScheduleID, COUNT(a.classScheduleId) FROM classSchedule s
LEFT JOIN Attendance a ON a.classScheduleId = s.classScheduleID
GROUP BY s.classScheduleId
这篇关于多个查询如何加入它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!