如何从更多列中选择但按 1 列分组? [英] How to Select from more columns but group by 1 column?

查看:23
本文介绍了如何从更多列中选择但按 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 列分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆