mysql 行转列 列转行 111
行转列
方法一:使用case…when…then 进行行转列
select student_id,
max(case when sc.course_id =1 then score else null end) as 'course_id = 1',
max(case course_id when 2 then score else null end) as 'course_id = 2',
max(case course_id when 3 then score else null end) as 'course_id = 3'
from tb_score
GROUP BY student_id
方法二:使用IF() 进行行转列:
select student_id,
max(if(course_id = 1,score,null)) as 'course_id = 1',
max(if(co
共有 0 条评论