简体   繁体   English

从每一行的另一列中减去一列的内容

[英]subtract the contents of one column from another columns in each row

I have a big MySQL table and I want to change the Description column. 我有一个很大的MySQL表,并且想更改Description列。

I want to delete the beginning of the every cell in each row that matches the value in the Name column, while the rest of the cell remains the same. 我想删除与“ Name列中的值匹配的每一行中每个单元格的开头,而其余单元格保持不变。

Please help. 请帮忙。 在此处输入图片说明

You could use update whete the locate for the name in desciption is 1 (at the begin of the description) 您可以使用update whe来描述名称中的位置为1(在描述的开头)

update my_table
set description = substr( description, length(name)+1)
where locate(description, name ) = 1

REPLACE is your friend. REPLACE是您的朋友。

use this to see the changes: 使用它来查看更改:

SELECT TRIM(REPLACE(Deescription,`name`,'')) as newField from youtTableName;

update your table 更新您的表

UPDATE youtTableName
SET `Deescription` =  TRIM(REPLACE(Deescription,`name`,''))
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM