表一 (t1):
表二 (t2):
表一转表二:
select
name,
sum(case subject when '语文' then score end) 语文,
sum(case subject when '数学' then score end) 数学,
sum(case subject when '英语' then score end) 英语
from t1 group by name;
表二转表一:
select name, '语文' subject , 语文 score from t2
union all
select name, '数学' subject , 数学 score from t2
union all
select name, '英语' subject , 英语 score from t2;