MySQL选择-将重复的行数据添加到新列

时间:2018-09-26 13:55:24

标签: mysql mariadb pivot-table

我在MySQL(MariaDB)中有这两个表:

表数据

+------+------+
|id    |object|
+------+------+
|1     |AFD   |
+------+------+
|2     |AFG   |
+------+------+
|3     |ASD   |
+------+------+
|4     |BDS   |
+------+------+
|5     |BDF   |
+------+------+

表格工作

+------+------+
|id    |action|
+------+------+
|1     |34    |
+------+------+
|1     |54    |
+------+------+
|1     |65    |
+------+------+
|2     |73    |
+------+------+
|2     |11    |
+------+------+

对于表DATA中的每个ID,表WORK中都有多个ID。 我需要这样的输出:

+------+------+-------+-------+-------+
|id    |object|action1|action2|action3|
+------+------+-------+-------+-------+
|1     |AFD   |34     |54     |64     |
+------+------+-------+-------+-------+
|2     |AFG   |73     |11     |NULL   |
+------+------+-------+-------+-------+
...

谢谢。

0 个答案:

没有答案