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
SELECT A.*, 所在班级总得分=(SELECT CASE WHEN A.姓名 = MAX(姓名) THEN CONVERT(VARCHAR(10),SUM(分数)) ELSE '' END FROM TAB B WHERE A.班级=B.班级) FROM TAB A ORDER BY A.班级, A.姓名 DESC
select
*,
[所在班级总分]=(select sum(分数) from table1 where 班级=T.班级)
from
table1 as T
(select sum(分数) from table1 where 班级=T.班级) else null end as 所在班级总分
from table T
FROM TAB A
ORDER BY A.班级, A.姓名 DESC