一、知识
这里的函数和一般意义的函数基本是等价的,给出相应的参数,获得相应的输出。由于函数这个话题太大,笔者由于水平问题,仅仅罗列出常用函数。
常用文本处理函数
UPPER() //将字符串转换为大写
LOWER()//转换为小写
LEFT()//返回字符串左边的字符
RIGHT()//返回字符串右边的字符
LENGTH//返回字符串的长度
LTRIM()//去掉字符串左边的空格
这里举一个小例子。输出全大写形式的prod_name
eg:
select upper(prod_name)
from tyqsl2.products
数值处理类函数
ABS()//绝对值
COS()
EXP()//返回一个数的指数值
SIN()
SQRT()//返回一个数的平方根
TAN()//正切
二、习题
select
cust_id,
cust_name,
concat(left(cust_contact,2),left(cust_city,3))
as user_login
from tyqsl2.customers
运用到了left函数,其中第一个参数是给定字符串,第二个是取前N个字符。
select
order_num,order_date
FROM tyqsl2.orders
where date_format(order_date,'%Y') = 2020
and date_format(order_date,'%m')= 1
order by 2