横纵表互转
select n.name,
sum(case course when '语文' then grade else 0 end) as 语文,
sum(case course when '数学' then grade else 0 end) as 数学,
sum(case course when '英语' then grade else 0 end) as 英语
from diy.new_table as n
group by name;
SELECT name,'语文' AS 科目,语文 AS 成绩 FROM new_table1 UNION ALL
SELECT name,'数学' AS 科目,数学 AS 成绩 FROM new_table1 UNION ALL
SELECT name,'英语' AS 科目,英语 AS 成绩 FROM new_table1
ORDER BY name,科目 DESC;