MySQL是否可以从数据库进行查询并将结果作为数组?
SELECT foo.name,
(
SELECT data
FROM bar
WHERE id=foo.userid
) data
FROM table1 foo;
+---------+------------------------+
| name | data |
+=========+========================+
| john | ['one','two','three'] |
| martha | ['one','five','nine'] |
+---------+------------------------+
谢谢!
答案 0 :(得分:2)
您可以使用GROUP_CONCAT
SELECT foo.name,(SELECT GROUP_CONCAT(data SEPARATOR ',')
FROM bar
WHERE id=foo.userid
GROUP BY data) AS data
FROM table1 foo;