SQL将一列与另一个表组合在一起并添加新列

时间:2018-06-07 03:18:27

标签: mysql join

抱歉标题不清楚。但我想制作具有编辑名称的列editor_article。只有id_article和parent_id中具有相同值的文章具有editor_article的名称,如果id_section = 29并且如果parent_id!= 0,则editor_article具有'0'值。编辑器列从逻辑列加入t_kolom.id_editor。

tbl_name:t_article
id_section  id_article      parent_id   editor
29          441             0           2
33          1093            18          2
33          18              0           0
29          3144            0           8
30          3136            0           0
31          3130            0           0
31          3140            3130        22
31          3141            3130        335
30          3142            3136        546

tbl_name:t_kolom
id_editor   name
1           john
2           gerrard
3           lukas
8           anthony
22          jimmy
335         eric
546         tyas

预期的产出:

id_section  id_article      parent_id   editor      editor_article
29          441             0           2           0
33          1093            18          2           0
33          18              0           0           gerrard
29          3144            0           8           0
30          3136            0           0           tyas
31          3130            0           0           jimmy,eric
31          3140            3130        22          0
31          3141            3130        335         0
30          3142            3136        546         0

0 个答案:

没有答案
相关问题