2019-07-17行列互换

SELECT 学号,'课程号0001','课程号0002','课程号0003'
from score1;

SELECT 学号,
(CASE 课程号 WHEN '0001' THEN 成绩 ELSE 0 END) AS '课程号0001',
(CASE 课程号 WHEN '0002' THEN 成绩 ELSE 0 END) AS '课程号0002',
(CASE 课程号 WHEN '0003' THEN 成绩 ELSE 0 END) AS '课程号0003'
FROM score1;

SELECT 学号,
MAX(CASE 课程号 WHEN '0001' THEN 成绩 ELSE 0 END) AS '课程号0001',
MAX(CASE 课程号 WHEN '0002' THEN 成绩 ELSE 0 END) AS '课程号0002',
MAX(CASE 课程号 WHEN '0003' THEN 成绩 ELSE 0 END) AS '课程号0003'
FROM score1
GROUP BY 学号;

你可能感兴趣的:(2019-07-17行列互换)