mysql 根据总分排名
SELECT t.*, @rank := @rank + 1 AS rank FROM ( SELECT @rank := 0 ) r, ( SELECT tas.id, tas.teacher_id, tas.average, tas.remark, tas.create_time, tas.course_id, su.user_name, ti.post, ti.SUBJECT FROM teacher_average_score tas LEFT JOIN sys_user su ON tas.teacher_id = su.user_id LEFT JOIN teacher_info ti ON tas.teacher_id = ti.user_id ORDER BY tas.average DESC ) AS t
mysql数据库查询表中相邻数据的差值
select a.time ,a.sum - b.sum sum,a.time,b.time from (select @arownum:=@arownum+1 rownum,sum ,time from summary_hour,(select @arownum:=0) t where energy_type= 1 order by time) a, (select @brownum:=@brownum+1 rownum ,sum,time from summary_hour,(select @brownum:=1) t where energy_type= 1 ORDEr by time) b where a.rownum = b.rownum;