mysql 学习笔记 - 初级
like 通配符
‘%’表示任意字符任意数量
select * from tb_products where prod_name LIKE 'jet%'; # 搜索以jet开头的数据
‘_’与‘%’用途一样但是只匹配单个字符而不是多个字符
select * from products where prod_name LIKE '_ ton anvil'; 搜索 ‘ton anvil’前边只有一个字符的数据
正则表达式
where 字句后边写‘REGEXP’ (BINARY 区分大小写)
select * from products where prod_name REGEXP '100|200|300' # | 表示or
匹配几个字符之一
where vend_name '[123] ton' # 等于'1|2|3 ton'
匹配特殊字符
where vend_name REDEXP '\\.' # \\转义之后就可以匹配特殊字符了



示例:
where prod_name REGEXP '\\([0-9] staicks?\\)'

示例:
where prod_name REGEXP '^[0-9]\\.'
拼接字段
可使用Concat()来拼接两个列
select Concat(vend_name, '(', vend_country, ')') as tb_name

浙公网安备 33010602011771号