其他分享
首页 > 其他分享> > 列数据转换成行表头

列数据转换成行表头

作者:互联网

参考于: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

在这里插入图片描述

在这里插入图片描述

标签:CASE,week,转换,name,WHEN,表头,course,END,成行
来源: https://blog.csdn.net/qq_32388061/article/details/118531830