学习参考https://www.bilibili.com/video/BV1Kr4y1i7ru?spm_id_from=333.999.0.0
目录
一.字符串函数

select concat(s1,s2 .. sn); #拼接
select lower(str); #转小写
select upper(str); #转大写
select lpad(str,n,pad); #左填pad至n
select rpad(str,n,pad); #右填pad至n
select trim(str); #去头尾空格
select substring(str,start,len); #返回str[start-1]~str[start+len-1]
二.数值函数

select ceil(x); #向上取整
select floor(x); #向下取整
select mod(x,y); #返回x/y的模
select rand(); #返回0-1的随机数
select round(x,y); #求x四舍五入的值,y是小数保留部分
三.日期函数

select curdate(); #返回当前日期
select curtime(); #返回当前时间
select now(); #返回但前日期和时间
select year(date); #获取年
select month(date); #获取月
select day(date); #获取日
select date_add(date,intervalexper type);
select datediff(date1,date2); #返回date2-date1之间的天数
四.流程函数

更C if switch 差不多。
本文详细介绍了SQL中的四种主要函数类别:字符串函数,如concat、lower和trim;数值函数,包括ceil、floor和mod;日期函数,如curdate、curtime和date_add;以及流程函数。这些函数在数据处理和查询中起到关键作用,帮助用户进行数据转换和计算。
547

被折叠的 条评论
为什么被折叠?



