逗号连接
select GROUP_CONCAT(colum) colums from table limit 1
查询成数组
SELECT CONCAT(
'[',
GROUP_CONCAT(JSON_OBJECT('name', name, 'phone', phone)),
']'
)
FROM person;
或者
SELECT JSON_ARRAYAGG(JSON_OBJECT('name', name, 'phone', phone)) from Person;
查询成对对象
SELECT
attr_id,
CONCAT(
'{',
GROUP_CONCAT(
CONCAT('"', id, '":"', attr_name, '"')
),
'}'
)
FROM
sys_commpara
GROUP BY
attr_id