【发布时间】:2015-11-25 15:12:32
【问题描述】:
这是我的数据结构:
table: items
id name category1 category2 category3
--------------------------------------------------
1 apple 1 57 NULL
2 banana 1 41 55
3 orange 1 53 NULL
4 strawberry 1 NULL NULL
想要的输出:
id name categories
--------------------------------------------------
1 apple 1,57
2 banana 1,41,55
3 orange 1,53
4 strawberry 1
这是我的查询:
SELECT items.*, CONCAT(category, ",", category2, ",", category3) AS categories FROM toom_items
有些东西不工作,我得到了这个:
id name categories
--------------------------------------------------
1 apple NULL
2 banana NULL
3 orange NULL
4 strawberry NULL
有什么想法吗?
【问题讨论】:
-
我建议你使用
concat_ws(),因为你只需要写一次分隔符,例如concat_ws(",", category, category2, category3)。 -
帮助了......谢谢!