what database are you using? if you are using SQL Server, you can try something likeselect 
sum(case when class = 1 then 1 else 0 end) as 1班,
sum(case when class = 2 then 1 else 0 end) as 2班,
sum(case when class = 3 then 1 else 0 end) as 3班,
count(*) as 小计
from student