select 年级,性别, avg(isnull(分数,0)) from tb group by 年级,性别为防止分数为null,可以用isnull函数做一下处理。
select 年级,性别,avg(分数) as '分数' from tb group by 年级,性别
select 年级 , 性别 , avg(分数) from student group by 年级 , 性别
SELECT 年级,avg(年龄)as 男同学平均年龄 into #t1 from student where 性别='男' group by 性别 SELECT 年级,avg(年龄)as 女同学平均年龄 into #t2 from student where 性别='女' select 年级,男同学平均年龄,女同学平均年龄 from #t1 a ,#t2 b where a.年级=b.年级 group by 性别
SELECT 年级,avg(年龄)as 男同学平均年龄 into #t1 from student where 性别='男' group by 性别 SELECT 年级,avg(年龄)as 女同学平均年龄 into #t2 from student where 性别='女' select 年级,男同学平均年龄,女同学平均年龄 from #t1 a ,#t2 b where a.年级=b.年级
up!按年级和性别分组查询然后用AVG函数取分数的平均值就可以了。
select 年级,性别, avg(isnull(分数,0)) from tb group by 年级,性别为防止分数为null,可以用isnull函数做一下处理。
group by 年级,性别
from student
group by 年级 , 性别
SELECT 年级,avg(年龄)as 男同学平均年龄 into #t1
from student
where 性别='男'
group by 性别
SELECT 年级,avg(年龄)as 女同学平均年龄 into #t2
from student
where 性别='女'
select 年级,男同学平均年龄,女同学平均年龄
from #t1 a ,#t2 b
where a.年级=b.年级
group by 性别
from student
where 性别='男'
group by 性别
SELECT 年级,avg(年龄)as 女同学平均年龄 into #t2
from student
where 性别='女'
select 年级,男同学平均年龄,女同学平均年龄
from #t1 a ,#t2 b
where a.年级=b.年级