gpt4 book ai didi

mysql 使用 where 子句计算另一个表中的行

转载 作者:行者123 更新时间:2023-11-30 21:39:02 25 4
gpt4 key购买 nike

大家好,需要一些帮助

如何使用 where 子句计算另一个表中的行数

所以我有两个表

学生表和考勤表我要统计该学生对应的所有考勤表

这是学生 table

enter image description here

这里是餐 table 签到

enter image description here

我试过了,但只是获取了出勤的学生

SELECT student.StudentID, student.`Name`, COUNT(attendance.AttendanceID) AS Total
FROM student
LEFT JOIN attendance ON student.StudentID = attendance.StudentID
where DateEntered between '2018-10-01' and '2018-10-01'
GROUP BY student.StudentID,student.`Name`

我想要帮助的是召集所有学生并计算他/她出勤的次数。用一个 where DateEntered

enter image description here

谢谢你的帮助..........

最佳答案

将条件放在左连接子句中:

SELECT student.StudentID, student.`Name`, COUNT(attendance.AttendanceID) AS Total
FROM student
LEFT JOIN attendance ON student.StudentID = attendance.StudentID
and DateEntered between '2018-10-01' and '2018-10-01'
GROUP BY student.StudentID,student.`Name`

关于mysql 使用 where 子句计算另一个表中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52594801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com