原表:
怎么行列进行转换像下图这样呢?
答:用case when函数
select username '姓名',
MAX(case course when '语文' then score else 0 end) '语文',
MAX(case course when '数学' then score else 0 end) '数学',
MAX(case course when '外语' then score else 0 end) '外语'
from tb_RowConvertToColumn
group by username
order by username;
即可实现