2017-10-13 81 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,')','')的解決方案 但是你的方法的工作原理是好。 –