你这个问题问的有点问题,应该把递减改成相减。
一般这种情况都是可以用动态隔间运算来解决的。可以参考下:环比-https://help.fanruan.com/finereport/doc-view-350.html
如果要用代码来解决的话,需要表之间的关联,例子:
SELECT t1.*, t2.*, t2.平均成绩 - t1.平均成绩 AS '差值'
FROM
( select t.classno,
cast(replace(t.classno,'Class','') as int) as 'no',
avg(t.grade) as '平均成绩'
from stscore t
group by t.classno
order by t.classno
) t1
left join
( select t.classno,
replace(t.classno,'Class','')+1 as 'no',
avg(t.grade) as '平均成绩'
from stscore t
group by t.classno
order by t.classno
) t2 on t1.no=t2.no
order by t1.classno;