MYSQL 如何在选择查询中使用修剪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3632760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MYSQL How to use trim in select query
提问by Bharanikumar
my table have set of records around 50,
我的桌子上有大约 50 条记录,
in the table i have column called USERNAME
, but some of username leading and trailing have the white space ,
在表中,我有一列名为USERNAME
,但一些用户名前导和尾随有空格,
so am not getting exact order result because of white space,
因为空白,所以没有得到确切的订单结果,
So tell me how to use the trim in SELECT
query ,
所以告诉我如何在SELECT
查询中使用修剪,
Thanks
谢谢
回答by OMG Ponies
You can use TRIMin the ORDER BY:
您可以在 ORDER BY 中使用TRIM:
ORDER BY TRIM(username)
...but this will only trim excess space on the left and right side of the text, not in between.
...但这只会修剪文本左侧和右侧的多余空间,而不是介于两者之间。
Using TRIM in the SELECT is as easy as:
在 SELECT 中使用 TRIM 非常简单:
SELECT TRIM(username) AS username
FROM your_table