删除重复的子字符串

编程入门 行业动态 更新时间:2024-10-25 14:27:04
本文介绍了删除重复的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我理解以下问题可能不是最佳做法。

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 |

更多推荐

删除重复的子字符串

本文发布于:2023-11-30 01:10:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!