gpt4 book ai didi

mysql - 从字符串 MYSQL 中删除多个尾随和前导关键字

转载 作者:搜寻专家 更新时间:2023-10-30 20:24:44 24 4
gpt4 key购买 nike

我有一个表,里面有这样的数据

 ---------------
|town |
---------------
|Longton North |
|Longton South |
|Longton North |
|Longton East |
|Longton West |
|East Valley |
|West Valley |
---------------

我知道如何使用

修剪字符串中的尾随和前导字符
TRIM(BOTH 'North' FROM town)

但我想从我的结果中修剪北、南、西、东。所以输出应该是这样的

 ---------
|town |
---------
|Longton |
|Longton |
|Longton |
|Longton |
|Longton |
|Valley |
|Valley |
---------

最佳答案

试试这个..这对你有用..

select 
trim(TRIM(BOTH 'South' FROM TRIM(BOTH 'North' FROM TRIM(BOTH 'East' FROM TRIM(BOTH 'West' FROM town))))) from tbl

或更具体

select trim(case 
when position('North' in town) > 0 then TRIM(BOTH 'North' FROM town)
when position('South' in town) > 0 then TRIM(BOTH 'South' FROM town)
when position('East' in town) > 0 then TRIM(BOTH 'East' FROM town)
when position('West' in town) > 0 then TRIM(BOTH 'West' FROM town) end)
from tbl

关于mysql - 从字符串 MYSQL 中删除多个尾随和前导关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41017326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com