case when后如何修改多条记录显示为一行——SQL练习

表如下:

img

查找每门课程的前3名。(显示形式:课程、第一名(姓名+分数) 、第二名(姓名+分数))

怎样调整语文一二三名显示在一行记录里

selecthttps://img-mid.csdnimg.cn/release/static/image/mid/ask/332924171086169.png "#left")
 a1.lesson_name 课程,
case 排序 when 1 then concat(a1.stu_name,'',a1.score)  end as 第一名,
case 排序 when 2 then concat(a1.stu_name,'',a1.score)  end as 第二名,
case 排序 when 3 then concat(a1.stu_name,'',a1.score)  end as 第三名
from (select stu.stu_name,les.lesson_name,sco.score,row_number()over(partition by lesson_name order by sco.score ) 排序 from t_student stu,t_lesson les,t_score sco where sco.stu_id=stu.stu_id and sco.lesson_id=les.lesson_id) a1;

img

你这玩意发问答里?