UPDATE IMAGES SET LI = (SELECT PLANT_DATA.M FROM PLANT_DATA WHERE PLANT_DATA.E LIKE "%," || IMAGES.PATH || ",%") WHERE EXISTS(SELECT * FROM PLANT_DATA WHERE PLANT_DATA.E LIKE "%," || IMAGES.PATH || ",%");
然后,填充xxx.jpg,**
UPDATE IMAGES SET LI = (SELECT PLANT_DATA.M FROM PLANT_DATA WHERE PLANT_DATA.E LIKE IMAGES.PATH || ",%") WHERE EXISTS(SELECT * FROM PLANT_DATA WHERE (LI IS NULL) AND PLANT_DATA.E LIKE IMAGES.PATH || ",%");
然后,**,xxx.jpg**
UPDATE IMAGES SET LI = (SELECT PLANT_DATA.M FROM PLANT_DATA WHERE PLANT_DATA.E LIKE "%," || IMAGES.PATH) WHERE EXISTS(SELECT * FROM PLANT_DATA WHERE (LI IS NULL) AND PLANT_DATA.E LIKE "%," || IMAGES.PATH);
最后,匹配没有逗号的(唯一)
UPDATE IMAGES SET LI = (SELECT PLANT_DATA.M FROM PLANT_DATA WHERE PLANT_DATA.E=IMAGES.PATH) WHERE EXISTS(SELECT * FROM PLANT_DATA WHERE (LI IS NULL) AND PLANT_DATA.E=IMAGES.PATH);
第二种方法:先替换再匹配
在每个字符串前后加上逗号,这样就不用逐步匹配啦 先
UPDATE PLANT_DATA SET E = "," || E || "," WHERE E <> "";
然后用上面的第一个就好,不用担心部分匹配的问题。
当然还有其他更好的办法就不啰嗦了
最后可以在**IMAGES**里用这个验证一下
SELECT GROUP_CONCAT(PATH), LI FROM IMAGES GROUP BY LI;