参考于:https://blog.csdn.net/rocling/article/details/82026704
将列数据转换成行表头
SELECT
course_num,
MAX(
CASE
WHEN week = ‘星期一’ THEN
course_name
END
) AS ‘星期一’,
MAX(
CASE
WHEN week = ‘星期二’ THEN
course_name
END
) AS ‘星期二’,
MAX(
CASE
WHEN week = ‘星期三’ THEN
course_name
END
) AS ‘星期三’,
MAX(
CASE
WHEN week = ‘星期四’ THEN
course_name
END
) AS ‘星期四’,
MAX(
CASE
WHEN week = ‘星期五’ THEN
course_name
END
) AS ‘星期五’
FROM
timetable
GROUP BY
course_num
ORDER BY
course_num