时间:2021-07-01 10:21:17 帮助过:3人阅读
表结构:

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 行转列
标签: