当一个字段里的数据是以逗号分隔时,利用GROUP_CONCAT(str)函数以及substring_index()函数,将其数据直接转换成以逗号相隔的字符串
记录sql如下
SELECT
s.id,
GROUP_CONCAT(d.dict_name) dict_name
FROM
sys_data_dict d
inner JOIN (
SELECT
id,
substring_index(
substring_index(
a.pro_property,
',',
b.help_topic_id + 1
),
',' ,- 1
) AS pro_property
FROM
tb_project_info a
JOIN mysql.help_topic b ON b.help_topic_id < (
length(a.pro_property) - length(
REPLACE (a.pro_property, ',', '')
) + 1
)
) s ON s.pro_property = d.dict_value
AND d.dict_code= 'project_proProperty'
and d.order_num!='0'
group by id
实现结果为:
因篇幅问题不能全部显示,请点此查看更多更全内容