2017-10-13 120 views
0

全部关闭。在Mysql Workbench中删除字符串的可变部分

我有一个两列的表。其中一个与customer_id和另一个与recetence_reason。我想从接受部分删除customer_id,但还没有找到一个有效的方法来实现。 为了避免混淆,我添加了一个图片clearify我的问题

Problem

+0

这个不清楚。字符串“接受基于reasonXX”是一个_static_吗?或者会有所不同? –

+0

和字符串'(customer id = xyz)'总是跟踪_reason文本_? –

+0

它会有所不同。所以有许多原因不同的原因。 –

回答

0

我想你已经尝试过substr()但也许你并不知道instr()。所以我会尝试一下:

select Customer_id, substr(acceptance_reason, 0, instr(acceptance_reason,"(")) as acceptance_reason from ... 
+0

我发现了Replace(accept_reason,CONCAT('(customer_id =',customer_id,')','')的解决方案 但是你的方法的工作原理是好。 –