% 匹配任意字符 _ 匹配任意单个字符
正则表达式: regexp
用法就是替换掉 like 的位置,后面配合正则表达式。
默认不区分大小写,如果区分的话添加关键字 binary 如: where *** regexp binary ‘jetpack .000’
select prod_name from products where prod_name regexp '.000' order by prod_name
or 匹配
select prod_name
from products
where prod_name regexp '1000|2000'
order by prod_name
结果与上图相同。
拼接串:concat() 把多个串连接起来形成一个较长的串。
select concat(vend_name,'(',vend_country,')')
from vendors
order by vend_name
rtrim() 删除右侧多余空格来整理数据
ltrim() 删除左侧多余空格来整理数据
trim() 删除左右两侧的空格
as 使用别名
执行算数运算
select prod_id,
quantity,
item_price,
quantity * item_price as expanded_price
from orderitems
where order_num = 20005
算数操作符支持 + - * / 。
测试计算:
select trim(' abc ')
select now()
left() 返回串左边字符
length() 返回串的长度
locate() 找出一个串的子串
lower() 将串转换为小写
right() 返回串右边的字符
soundex() 返回串的 soundex 值
substring() 返回子串的字符
upper() 将串转换为大写
soundex 是个将任何文本串转换为描述其语音表示的字母数字模式的算法。
select cust_name, cust_contact
from customers
where cust_contact = 'y lie'
select cust_name, cust_contact
from customers
where soundex(cust_contact) = soundex('y lie')
时间函数:
date() 主要是日期
time() 主要是时间
now() 获得当前时间
数值处理函数:
abs() 返回一个数的绝对值
cos() 返回一个角度的余弦值
exp() 返回一个数的指数值
mod() 返回除操作的余数
pi() 返回圆周率
rand() 返回一个随机数
sin() 返回一个角度的正弦
sqrt() 返回一个数的平方根
tan() 返回一个角度的正切
聚集函数:
avg() 返回某列的平均值
count() 返回某列的行数
max() 返回某列的最大值
min() 返回某列的最小值
sum() 返回某列值之和,忽略列值为 null 的行。
