SQL query construction - separate data in a column into two columns

后端 未结 4 915
北恋
北恋 2021-01-25 08:30

I have a column that contains links. The problem is that the titles of the links are in the same column, so it looks like this:
linktitle|-|linkurl
I want l

相关标签:
4条回答
  • 2021-01-25 08:33
    SELECT substring(field_name, 1, locate('|-|', field_name)-1) as title,
    substring(field_name, locate('|-|', field_name)+3) as linkurl
    
    0 讨论(0)
  • 2021-01-25 08:35
    UPDATE TableName 
    SET LinkTitle = Substring(LinkColumn, 0, InStr(LinkColumn, '|-|') - 1),
    LinkUrl = Substring(LinkColumn, InStr(LinkColumn, '|-|') + 3)
    

    With LinkColumn being the currently existing column, and LinkTitle & LinkUrl being where you want to store the separated data.

    0 讨论(0)
  • 2021-01-25 08:43
    UPDATE tablename
    SET linktitle = SUBSTRING_INDEX(link , '|-|', 1 )
    linkurl = SUBSTRING_INDEX(link , '|-|', -1 )
    
    0 讨论(0)
  • 2021-01-25 08:52

    The query that solved this problem looks like this:

    UPDATE jos_fabrik_posesapp
    SET linktitle = Left(poselink, InStr(poselink, '|-|')-1),
    linkurl = Substring(poselink, InStr(poselink, '|-|') + 3)
    

    I'm not quite sure what it means, but it worked. Thanks for all replies!

    0 讨论(0)
提交回复
热议问题