MySQL-如果以数字或特殊字符开头 [英] MySQL - If It Starts With A Number Or Special Character

查看:286
本文介绍了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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆