sql 关联查询——字符数组id一一对应id(FIND_IN_SET函数和substring函数的使用)
表一:bd_supplier 字段:id、supname
表二:plan_pur_dtl 关联字段:suppliser。这里存的是string 而且格式是[“213”,“456”,“485”]
SQL:
SELECT
-- COUNT( a.id ),
a.supname
-- a.id
-- b.*
FROM
bd_supplier a
LEFT JOIN plan_pur_dtl b
-- 使用FIND_IN_SET(id,[id1,id2])函数
-- id:为条件id, id1是需要去匹配的id
-- SUBSTR函数数据清晰为 1597528532244824065, 1601414721985122306格式
ON FIND_IN_SET( a.id, SUBSTR( b.supplier, 2, length( supplier )- 2 ) )
WHERE
b.supplier IS NOT NULL
-- bd_supplier条件筛选
-- AND a.supname = '' AND a.id=