列数据转换成行表头

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

列数据转换成行表头

列数据转换成行表头

上一篇:LeetCode 【困难】数据库-第618:学生地理信息报告(分组行列转换)


下一篇:php count聚合函数加上条件判断读取数据