杨魅力
mysql中,查询纵向转横向可用case when语句。工具:mysql 5.6步骤:1、student表中有如下数据:2、纵向显示每个班级的总分,用如下语句:1select class,sum(score) from student group by class;查询结果:3、要将结果横向显示,则用case when语句,语句如下:12345select sum(case when class='一年一班' then score else 0 end) 一年一班成绩,sum(case when class='一年二班' then score else 0 end) 一年二班成绩,sum(case when class='一年三班' then score else 0 end) 一年三班成绩from student;查询结果: