本文介绍了MySQL-如果以数字或特殊字符开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT *
FROM `thread`
WHERE forumid NOT IN (1,2,3) AND IF( LEFT( title, 1) = '#', 1, 0)
ORDER BY title ASC
我有这个查询,如果它以#开头,它将选择某些内容.我想做的是,如果#是一个值,它将查找数字和特殊字符.或任何不正常的字母.
I have this query which will select something if it starts with a #. What I want to do is if # is given as a value it will look for numbers and special characters. Or anything that is not a normal letter.
我该怎么做?
推荐答案
如果要选择标题"不是以字母开头的所有行,请使用REGEXP:
If you want to select all the rows whose "title" does not begin with a letter, use REGEXP:
SELECT *
FROM thread
WHERE forumid NOT IN (1,2,3)
AND title NOT REGEXP '^[[:alpha:]]'
ORDER BY title ASC
- 否的意思是不是"(显然;))
- ^ 表示开头为"
- [[:: alpha:]] 表示仅字母字符"
- NOT means "not" (obviously ;))
- ^ means "starts with"
- [[:alpha:]] means "alphabetic characters only"
在MySQL手册中找到有关 REGEXP的更多信息.
Find more about REGEXP in MySQL's manual.
这篇关于MySQL-如果以数字或特殊字符开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!