select 系名,count(*) as 系人数, avg(年龄) as 系平均年龄
from Student group by 系名
select 班级名,count(*) as 班级人数, avg(年龄) as 班级平均年龄
from Student group by 班级名
如果系名和班级名字段类型一样,可以用union all 把两个表连起来。如果不一样,可以把班级名转换成和系名字段类型一样,再用union all连接起来。
系和班需要分两个不同语句来写
select className,count(*) as number, avg(age) as averageAge
from Student group by className
select departmentName,count(*) as number, avg(age) as averageAge
from Student group by departmentName