答案 0 :(得分:2)
使用 ROLLUP 并将联合添加到表格中
declare @mytable as table(classname varchar(100),studentname varchar(100))
insert into @mytable values
('10th','Hakim'),
('10th','Fathi'),
('9th','Saber'),
('9th','Wahid'),
('9th','Isamïl')
select * from
(select classname,total=convert(varchar(100),count(1)) from @mytable
GROUP BY ROLLUP(classname)
union
select * from @mytable) v
where classname is not null
order by classname,isnumeric(total)