本文介绍了删除重复的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我理解以下问题可能不是最佳做法。
I understand that the following question may not be best practice.
我有一个具有以下结构的表,关键字列和标题列连接到mashup专栏。
I have a table that has the following structure, the keyword column and title column concat into the mashup column.
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon Watermelon | +------------+------------+-----------------------+我想知道是否有重复字符串的方法。所以我的表格看起来更像下面的内容:
I would like to know if there is a way of "deduping" the string. So my table will look more like the below:
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon | +------------+------------+-----------------------+这可能吗?我似乎无法找到解决方案。谢谢!
Is this possible? I can't seem to find a solution. Thanks!
编辑:
+------------+------------+-------------+-----------------------------+ | Keyword | Title | Another | Mashup | +------------+------------+-------------+-----------------------------+ | Green | Green | Pink | Green Green Pink | | Green | Watermelon | Yellow | Green Watermelon Yellow | | Watermelon | Watermelon | Black | Watermelon Watermelon Black | +------------+------------+-------------+-----------------------------+推荐答案
试试这个:
UPDATE tableA SET Mashup = IF(Keyword = Title, Keyword, CONCAT(Keyword, ' ', Title));检查 SQL FIDDLE DEMO
输出
| KEYWORD | TITLE | MASHUP | |------------|------------|------------------| | Green | Green | Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon |更多推荐
删除重复的子字符串
发布评论