跟上一道题差不多,考点和逻辑都差不多。 方法一:group by +max()+if select 学号, max(if(课程="语文",成绩,0)) as 语文成绩, max(if(课程="数学",成绩,0)) as 数学成绩 from 成绩表 group by 学号 order by 学号 方法二:group by +max()+case when then end select 学号, max(case when 课程="语文" then 成绩 end) as 语文成绩, max(case when 课程="数学" then 成绩 end) as 数学成绩 from 成绩表 group by 学号 order by 学号