MySQL MySQL查询返回包含空格的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6969315/
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 Query to return rows that contain whitespace
提问by Andy Davies
I would like to run a query on a MySQL database table to return all the rows where the column data has white space. e.g.:
我想对 MySQL 数据库表运行查询以返回列数据具有空格的所有行。例如:
Usernames
andy davies
peter
geoff smith
steve
bob paul
用户名
安迪·戴维斯
彼得
杰夫·史密斯
史蒂夫
鲍勃·保罗
The query would only return 'andy davies', 'geoff smith', 'bob paul' and ignore 'peter' and 'steve'
查询只会返回“andy davies”、“geoff smith”、“bob paul”,而忽略“peter”和“steve”
Any ideas?
有任何想法吗?
回答by Ignacio Vazquez-Abrams
SELECT ...
...
WHERE username LIKE '% %'
回答by Andy Davies
INSTR() returns the position of the specified substring in the given string. Use it in the WHERE conditional.
INSTR() 返回给定字符串中指定子字符串的位置。在 WHERE 条件中使用它。
SELECT * FROM table WHERE INSTR(`username`, ' ') > 0
回答by Jose Adrian
An idea:
一个主意:
SELECT names FROM tbl_name WHERE names LIKE "% %";