本文介绍了如何从更多列中选择但按 1 列分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT        studentnum
FROM            Atten
WHERE        (att = 'Yes') AND (unitCode = 'MMA1034')
GROUP BY studentnum
HAVING        (COUNT(*) < 4)

如何选择更多列?例如,student_name 也是?

How do i select more columns? eg, student_name as well?

推荐答案

如果学生信息在Student表中,那么查询可能是这样的:

If student information is in Student table, then query may look like this:

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

这篇关于如何从更多列中选择但按 1 列分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 01:33