dove2199 2018-07-01 11:02
浏览 108
已采纳

从Mysql中的一列中删除子字符串

I want to delete a part of the substring from my table's column

For example, I have a structure like the following:

id | Col1                                      
____________________________________________________________
1  | The string I want and the string I don't   

And I need to update my table such that:

id | Col1                                       
____________________________________________________________
1  | The string I want 

I tried using the following code:

$var = "UPDATE mytable
  SET col1 = replace(col1,col1(SUBSTRING(col1,19),'')";

But this won't work!

  • 写回答

1条回答 默认 最新

  • duan205571 2018-07-01 11:14
    关注

    Try this query to separate address:

    UPDATE mytable as a 
    INNER JOIN
        (SELECT 
            id,
            Address1, 
            LEFT(Address1, 40 -1) as newCol1,
            substring(Address1, 40) as newCol2
        FROM mytable 
        where length(Address1) > 40) b 
    on a.id=b.id 
    set Address1=newCol1,Address2=newCol2;
    

    if there is any concern about above query please let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?