我需要一点帮助以下查询。我需要找到:
每个校区每学期的平均人数
我的表结构是:
在campus
,year
,semester
和batch
的帮助下,我可以识别每个独特的学期。我的student_id
更多地在数据库中重复。
我做了以下但是没有帮助。所以我需要一些帮助。
SELECT semester,year,campus
FROM regestration
GROUP BY semester, year, campus
ORDER BY count(*) desc
答案 0 :(得分:0)
尝试类似:
SELECT year,campus, AVG(CountOfStudents)
FROM
(
SELECT semester,year,campus, count(*) as CountOfStudents
FROM regestration
GROUP BY semester, year, campus
) t
GROUP BY year, campus
答案 1 :(得分:0)
要获得每个学期每个校区的学生人数,您需要在查询中添加COUNT(*):
SELECT semester, year, campus, COUNT(*) as students
FROM registration
GROUP BY semester, year, campus
我不知道你想要的平均值。
答案 2 :(得分:0)
怎么样
select avg(students), campus from (
select count(student_id) students, campus from registration
group by semester, year, campus
) group by campus