MySQL实现两个字符串(两个字符串均用,号分隔)提取交集并拼接输出

eg:{1,'title1','test,test1,test2,test3'},{2,'title2','test,test2,test4,test5'}
输出:{'title2','test含义,test2含义'}


SELECT
        t.setting_title,
        GROUP_CONCAT(lv.meaning) supplyTypeNames
        FROM
        (
        SELECT
        substring_index( substring_index( ssh.supply_type, ',', ht.help_topic_id + 1 ), ',',- 1 ) AS split_supply_type,
        ssh.setting_title
        FROM
        srm_spe_setting_head ssh
        JOIN mysql.help_topic ht ON ht.help_topic_id <![CDATA[ < ]]> ( length( ssh.supply_type ) - length( REPLACE ( ssh.supply_type, ',', '' ))+ 1 )
        where ssh.setting_head_id <![CDATA[ < ]]> 1
        ) t
        left join lookup_values lv on lv.lookup_code=t.split_supply_type and lv.lookup_type='CLASSIFICA'
        WHERE
        EXISTS (
        SELECT
        1
        FROM
        (
        SELECT
        substring_index( substring_index( 'test,test1,test2,test3', ',', ht.help_topic_id + 1 ), ',',- 1 ) AS split_supply_type
        FROM
        mysql.help_topic ht
        WHERE
        ht.help_topic_id <![CDATA[ < ]]> ( length( 'test,test1,test2,test3' ) - length( REPLACE ( 'test,test1,test2,test3', ',', '' ))+ 1 )) t1
        WHERE
        t1.split_supply_type = t.split_supply_type
        )
        group by t.setting_title

 

posted @ 2021-08-09 10:47  哎丫丫呀喂  阅读(851)  评论(0编辑  收藏  举报