MySQL score ranking and use of lag function method

- the SELECT * the FROM employment_direction_recommend_table the GROUP BY student_name the HAVING COUNT (student_name)> 1; 
- the SELECT * in the FROM employment_direction_recommend_table the WHERE student_name ( 'East Green beams', 'Sangzhe green') 

- to calculate grade point average and ranking 
the SELECT a.student_name , 

- on @lagfield as a score, 

Case  When a.` GPA ` = @lagfield  the then  @rowNum  the else ( @rowNum : = @rowNum + . 1 ) the END  AS ` rank `, 

@lagfield : = a.` GPA ` AS score 

- (@rowNum:=@rowNum+1) as `名次`   
FROM(
select student_name,
round((avg(required_synthesize)+avg(major_synthesize)+avg(synthesize_appraisal))/3,2) as `平均成绩`
from employment_direction_recommend_table b GROUP BY student_name order by `平均成绩` desc
) a,(SELECT (@rowNum :=0)) b,(select @lagfield:=0) r

 

Guess you like

Origin www.cnblogs.com/wuzaipei/p/12732634.html