我理解以下问题可能不是最佳做法。
我有一个具有以下结构的表,关键字列和标题列连接到mashup列。
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon Watermelon | +------------+------------+-----------------------+
我想知道是否有一种方法可以重复使用"字符串。所以我的表格看起来更像下面的内容:
+------------+------------+-----------------------+ | Keyword | Title | Mashup | +------------+------------+-----------------------+ | Green | Green | Green | | Green | Watermelon | Green Watermelon | | Watermelon | Watermelon | Watermelon | +------------+------------+-----------------------+
这可能吗?我似乎无法找到解决方案。谢谢!
编辑:
+------------+------------+-------------+-----------------------------+ | Keyword | Title | Another | Mashup | +------------+------------+-------------+-----------------------------+ | Green | Green | Pink | Green Green Pink | | Green | Watermelon | Yellow | Green Watermelon Yellow | | Watermelon | Watermelon | Black | Watermelon Watermelon Black | +------------+------------+-------------+-----------------------------+
答案 0 :(得分:6)
试试这个:
UPDATE tableA
SET Mashup = IF(Keyword = Title, Keyword, CONCAT(Keyword, ' ', Title));
<强>输出强>
| KEYWORD | TITLE | MASHUP |
|------------|------------|------------------|
| Green | Green | Green |
| Green | Watermelon | Green Watermelon |
| Watermelon | Watermelon | Watermelon |