函数应用(MySQL)

--数值类函数
--绝对值

select abs(-1)

--seiling ceil 向上取整

select ceil(1.1)

--floor 向下取整

select floor(1.9);

--四舍五入

select round(1.17, 1);

--rand 随机数

select rand(rand()*1000);

--字符串函数 utf8mb3 utfmb4
select length('小三')
--查找字符数量

--select char_length('小三');

--模糊查询

select concat('%','小','%');

--查询字段为3

select * from t_student where char_length(sname)=3;

--插入

select insert('abc',1,1,'f');

--大小写

select lower('ABC');
select upper('abc');

--拿出每个人的姓氏 左边取left 右边取right

select left('彭某某',1)
select left(sname,1) from t_student;

--trim 删除字符串左右的空格

select trim('a b c');

--替换

select replace(' a b c ',',','') name;

--截取

SELECT SUBSTRING('Quadratically',5,2);

--日期和时间相关函数
SELECT SUBSTRING('Quadratically',5,2);
--获取当前时间

select now();

--当前日期

select current_date;

--当前时间戳

select current_timestamp;

--当前时间

select current_time;

--系统时间

select susdate();

--年月日

year
month
day

--查看年

select year

--查看月

select month(now());

--查看日

select day(now());

--当天英文名

select dayname(now());

--在这个月是第几天

select dayofmonth(now());

--在今年是第几天

select dayofyear(now());

--查看今天星期几

select dayofweek(now());

--添加3年

select date_add(now(),interval 3 year);

--添加3月

select date_add(now(),interval 3 month);

--添加3秒

select date_add(now(),interval 3 second);

--添加三分钟

select data_add(now(),interval 3 minute);

--两个日期求差值

select datediff(now(),'2020/1/1')/365

--格式化时间

select date_format('2020/1/1','%W %m %y')

--如果是空值 显示其他值
select ifnull(name,'没有名字')

select if(2>1,'yes','no');

select md5(123456);
相关推荐
sevenll0715 分钟前
DocKit agentic MongoDB GUI 客户端 - 用自然语言和你的数据对话
数据库·mongodb·nosql·agent·桌面客户端
团象科技26 分钟前
从一线实操案例拆解不同出海团队落地海外VPS运维独立站的路径细节
大数据·数据库·人工智能
小马爱打代码41 分钟前
框架 - 组件 - 中间件:生产级参数配置指引
数据库·中间件
asdfg12589631 小时前
一文通俗理解JDBC中的核心概念+案例
java·数据库·oracle·jdbc
点灯小铭1 小时前
基于单片机与DAC0832的双路波形信号发生系统设计
数据库·单片机·mongodb·毕业设计·课程设计·期末大作业
小陈phd1 小时前
Text2SQL智能体学习笔记(二)——NL2SQL落地的隐形基石:元数据库
数据库·笔记·学习
霸道流氓气质1 小时前
阿里云 OSS 从零到实战:概念、配置与 Spring Boot 集成指南
数据库·spring boot·阿里云
茉莉玫瑰花茶1 小时前
综合案例 - AI 智能租房助手 [ 4 ]
数据库·python·ai·langgraph
可乐ea1 小时前
【Spring Boot + MyBatis|第4篇】MyBatis 动态 SQL:if、where、foreach 使用详解
java·spring boot·后端·sql·mybatis
ULIi096kr1 小时前
MySQL查看表创建时间、修改时间、最后更新时间(精准排查僵尸表)
数据库·mysql