如何删除查询中的第一个单词 [英] How to remove the first word in an query
本文介绍了如何删除查询中的第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除MySQL查询中字段的第一个单词? 我尝试使用SUBSTRING_INDEX,但没有结果.该字段为varchar,可以包含字母和数字
How can I remove the first word of an field in an MySQL query? I have tried to work with SUBSTRING_INDEX but no result. The field is varchar and can contain both letters and numbers
示例:
PWS 20110804 Pos. 04
应该变成20110804 Pos. 04
PWS Pos. 04
应该成为Pos. 04
PWS AA.0804 Pos. 04
应该成为AA.0804 Pos. 04
推荐答案
使用 SUBSTRING()
与 LOCATE()
,如果您认为单词"由单个空格字符绑定. LOCATE()
将返回其第一个参数的第一个匹配项的位置.
Use SUBSTRING()
with LOCATE()
, if you consider a "word" to be bound by a single space character. LOCATE()
will return the position of the first occurrence of its first argument.
SELECT SUBSTRING(column, LOCATE(' ', column)+1);
示例:
mysql> SELECT SUBSTRING('this has four words', LOCATE(' ' ,'this has four words')+1);
+------------------------------------------------------------------------+
| SUBSTRING('this has four words', LOCATE(' ' ,'this has four words')+1) |
+------------------------------------------------------------------------+
| has four words |
+------------------------------------------------------------------------+
这篇关于如何删除查询中的第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文