1、原表select * from test
2、一个人的每个科目作为一行记录 改为一个人的所有科目作为一行记录
方式1
select name,
sum(case when subject='语文' then score else 0 end) as chinese,
sum(case when subject='数学' then score else 0 end) as math
from test
group by name
方式二示例
multiIf、if写法
方式1
select name,
sum(case when subject='语文' then score else 0 end) as chinese,
sum(case when subject='数学' then score else 0 end) as math
from test
group by name
方式二示例
multiIf、if写法