想写一个sql语句查询结果如下: 分数 班级 姓名 所在班级总分 60 1班 张三 160 60 1班 王五 40 1班 李四 20 2班 吴涛 113 50 2班 刘一 43 2班 将二 79 3班 小煤 189 80 3班 刘涛 30 3班 李力 select *, [所在班级总分]=(select sum(分数) from table1 where 班级=T.班级) from table1 as T 这种结果表本身就是没有意义的 select *,case when 姓名 in(select max(姓名) from table1 group by 班级) then (select sum(分数) from table1 where 班级=T.班级) else null end as 所在班级总分 from table T