1.列轉行
select class_id,MAX(CASE kemu when '語文' then score ELSE 0 end)as '語文' ,
MAX(CASE kemu when '數學' then score ELSE 0 end)as '數學' ,
MAX(CASE kemu when '英語' then score ELSE 0 end)as '英語'
FROM scoreinfo GROUP BY stuent_id

2.依據查詢的結果機創建一個新表
CREATE table pei_new (select class_id,MAX(CASE kemu when '語文' then score ELSE 0 end)as '語文' ,
MAX(CASE kemu when '數學' then score ELSE 0 end)as '數學' ,
MAX(CASE kemu when '英語' then score ELSE 0 end)as '英語'
FROM scoreinfo GROUP BY stuent_id)

3.復制一張表 ,只復制表結構
CREATE table pei_new like scoreinfo;
4.行轉列

SELECT class_id,'語文' as 科目,語文 as 成績 FROM pei_new
UNION
SELECT class_id,'數學',數學 FROM pei_new
union
SELECT class_id,'英語',英語 FROM pei_new
