-- WH 拆分成多行 数据 20230519
SELECT * FROM (
SELECT SKU,Primary_Warehouse, SUBSTRING_INDEX(SUBSTRING_INDEX(WH, ',', n.digit+1), ',', -1) as WH
FROM TMP_WH_SKU
INNER JOIN (
SELECT 0 digit UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4
) n
ON CHAR_LENGTH(WH) - CHAR_LENGTH(REPLACE(WH, ',', '')) >= n.digit
WHERE WH != Primary_Warehouse
) SKUs
where SKUs.WH != SKUs.Primary_Warehouse;