MySQL-代码-将字符串列表转成临时表-用户判断业务中不存在的数据
SELECT
substring_index( substring_index( a.user_id, ',', b.help_topic_id + 1 ), ',', - 1 ) AS user_id
FROM
( SELECT "chenhaijunaoc,daijunaoc,huyuebin,jdr153,jdr213,jdr242,jdr260,jdr300,jdr308,jdr324,jdr340,linjiabin,liyongaoc,lvmin,xieshibiao,yanggui,zhouyigui" AS user_id FROM DUAL ) a
INNER JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.user_id ) - length( REPLACE ( a.user_id, ',', '' ) ) + 1 )
应用:
查询数据库中没有的数据
SELECT
temp.user_id
FROM (SELECT substring_index( substring_index( a.user_id, ',', b.help_topic_id + 1 ), ',', - 1 ) AS user_id FROM ( SELECT "chenhaijunaoc,daijunaoc,huyuebin,jdr153,jdr213,jdr242,jdr260,jdr300,jdr308,jdr324,jdr340,linjiabin,liyongaoc,lvmin,xieshibiao,yanggui,zhouyigui" AS user_id FROM DUAL ) a
INNER JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.user_id ) - length( REPLACE ( a.user_id, ',', '' ) ) + 1 )
) temp WHERE NOT EXISTS ( SELECT 1 FROM p_user_information WHERE enterprise_id = "jinlingliliansishuzh" AND user_id = temp.user_id )
前提:
1、如果help_topic表没有数据不行,换个表也不行(应该是需要连续行要多于多余分割数量的表)
2、逗号分割个数应该少于504个 (mysql.help_topic中help_topic_id个数), https://blog.csdn.net/zhaoxiang10052111/article/details/80003765
正文到此结束