Split column string into multiple columns strings

前端 未结 2 1273
盖世英雄少女心
盖世英雄少女心 2021-01-26 14:22

I have a entry in the table that is a string which is delimited by semicolons. Is possible to split the string into separate columns? I\'ve been looking online and at stackoverf

2条回答
  •  不知归路
    2021-01-26 14:43

    Please take a look at how I've split my coordinates column into 2 lat/lng columns:

    UPDATE shops_locations L 
    LEFT JOIN shops_locations L2 ON L2.id = L.id
    SET L.coord_lat = SUBSTRING(L2.coordinates, 1, LOCATE('|', L2.coordinates) - 1), 
    L.coord_lng = SUBSTRING(L2.coordinates, LOCATE('|', L2.coordinates) + 1)
    

    In overall I followed UPDATE JOIN advice from here MySQL - UPDATE query based on SELECT Query and STR_SPLIT question here Split value from one field to two

    Yes I'm just splitting into 2, and SUBSTRING might not work well for you, but anyway, hope this helps :)

提交回复
热议问题