业务表(A)数据:
id |
value |
1 |
01,02 |
2 |
03,04 |
字典表 (B) 数据:
id |
value |
01 |
春 |
02 |
夏 |
03 |
秋 |
04 |
冬 |
期望得到的结果:
id |
value |
1 |
春,夏 |
2 |
秋,冬 |
方法一:
SELECT A.id, GROUP_CONCAT(B. VALUE)FROM A LEFT JOIN B ON FIND_IN_SET(B.id, A. VALUE)<>0GROUPBY A.id
方法二:
SELECT a.id, GROUP_CONCAT(B. VALUE) value FROM(SELECT A.id, SUBSTRING_INDEX( SUBSTRING_INDEX( A. VALUE ,',', c.help_topic_id+1),',',-1) VALUE FROM A LEFT JOIN mysql.help_topic c ON c.help_topic_id< LENGTH(A. VALUE)- LENGTH(REPLACE(A. VALUE,',','')+1)) a LEFT JOIN B ON a. VALUE = B.idGROUPBY a.id