输入banner图图片脚本导航/分类

SQL 行转列

表结构:

技术分享

subject 科目

yw 语文

sx 数学

表数据:

技术分享

转换SQL:

1 select name, 
2 max(case subject when yw then score else ‘‘ end) as yw , 
3 max(case subject when sx then score else ‘‘ end) as sx 
4 from student_score group by name

转换结果:

技术分享

转换过程:

根据学生姓名进行分组,并通过max取出相应科目的值 

技术分享

 sql语句中有错误,你发现了吗?

SQL 行转列

标签: