日期:2014-05-19  浏览次数:20363 次

一条麻烦但适用的sql,求解!
学生信息表(student)
UserID  
Name(学生姓名)

学生成绩表(Score)
ID
UserID
Score(总分)
Addtime(时间)

学生表数据是固定的,成绩表一个月会录一次学生成绩,现在想按照进步最大的排序,请问如何实现?
进步最大计算:   (本月Score-上月Score)/上月Score

------解决方案--------------------
select month(a.atime), a.sid ,(case when a.score =0 or b.score=0 then 0 else (b.score-a.score)*1.0/100 end) as progress from score a join
score b on a.sid=b.sid and month(a.atime)=month(b.atime)-1