提取表中每个分组的前几条数据 select 课程, sum(奖金) as 奖金 from ( select 课程, 学号, 成绩 from 考试 as a where ( select count(*) from 考试 where 课程 = a.课程 and 学号 a.学号 and 成绩 a.成绩 ) 3 www.2cto.com ) as b group by 课程
提取表中每个分组的前几条数据
select 课程,
sum(奖金) as 奖金
from ( select 课程,
学号,
成绩
from 考试 as a
where ( select count(*)
from 考试
where 课程 = a.课程
and 学号 a.学号
and 成绩 > a.成绩
)
) as b
group by 课程