小编Lan*_*anw的帖子

如何将多行数据放入多列的行中

我有一个像这样的 MySQL 表:

User_Id  course_name     course_location   course_id
1        course name 1   location 1        1
1        course name 2   location 2        2
1        course name 3   location 1        3
2        course name 2   location 1        2
2        course name 4   location 4        4
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到这样的数据:

User_id  course 1       course2        course3        course4
1        yes-location1  yes-location2  yes-location1  NULL
2        NULL           yes-location1  NULL           yes-location4
Run Code Online (Sandbox Code Playgroud)

mysql pivot

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

mysql ×1

pivot ×1