在MySQL中获取空格之前的所有字符 [英] Get all characters before space in MySQL
本文介绍了在MySQL中获取空格之前的所有字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取字段中空格之前的所有字符
I would like to get all the characters in a field before a space
例如,如果field1
是"chara ters"
我希望它返回"chara"
此select语句是什么样的?
What would this select statement look like?
推荐答案
SELECT LEFT(field1,LOCATE(' ',field1) - 1)
请注意,如果所讨论的字符串不包含空格,则将返回一个空字符串.
Note that if the string in question contains no spaces, this will return an empty string.
这篇关于在MySQL中获取空格之前的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文