SELECT studentnum
FROM Atten
WHERE (att = 'Yes') AND (unitCode = 'MMA1034')
GROUP BY studentnum
HAVING (COUNT(*) < 4)
如何选择更多列?例如,student_name 也是?
最佳答案
如果学生信息在 Student 表中,则查询可能如下所示:
SELECT student_name, student_birth_day, studentnum
FROM Student S
RIGHT JOIN (
SELECT studentnum, count(*) as cnt
FROM Attendance
WHERE (attStatus = 'Yes')
AND (unitCode = 'MMA1034')
GROUP BY studentnum
HAVING (COUNT(*) < 4)
) A
ON A.studentnum = S.studentnum
关于sql-server - 如何从更多列中选择但按 1 列分组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7564285/