查询以删除字符串中最后一个逗号后的所有字符 [英] query to remove all characters after last comma in string
本文介绍了查询以删除字符串中最后一个逗号后的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有此类数据的mysql表
i have a mysql table with this sort of data
TACOMA, Washington, 98477
现在我有成千上万个这样的行.我希望以这样的方式处理数据:
Now i have thousands of such rows. I want the data to be manipulated in such a manner that it appears like:
TACOMA, Washington
是否可以通过mysql进行操作,还是必须手动进行操作?
Is it possible though mysql or do i have to manually do it.
推荐答案
您可以使用:
SELECT SUBSTRING_INDEX('TACOMA, Washington, 98477', ',', 2)
您可以在此处了解更多信息.
You can read more here.
和更新语句:
UPDATE my_table
SET my_col = SUBSTRING_INDEX(my_col, ',', 2)
需要用表名替换my_table
并用要更新的列替换my_col
的地方.
Where you need to replace my_table
with your table name and my_col
with the column you need to be updated.
这篇关于查询以删除字符串中最后一个逗号后的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文