我有一个包含类似数据的表格
---------------
|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
一次修剪多个字符怎么样?
SELECT colName, TRIM(colName,'North South East West') as MyNew.colName
FROM DataTable