当前位置:网站首页>MYSQL关键字
MYSQL关键字
2022-07-02 06:48:00 【张意的博客】
1.TIMESTAMPDIFF
- 作用
*计算函数日期或日期表达式之间的整数差
TIMESTAMPDIFF(PARAM,DATETIME1,DATETIME2)
#DATETIME1,和DATETIME2之间的时间差,以param为时间单位
#支持的时间单位具体有:
#FRAC_SECOND 间隔毫秒,*SECOND 秒,*MINUTE 分钟,*HOUR 小时,*DAY 天,*WEEK 星期,*MONTH 月,#*QUARTER 季度,*YEAR 年
2.AVG
- 作用
*求平均值,可以求某一个字段的平均值,也可以求某一个函数公式计算结果值的所有值的平均值
AVG(字段)
AVG(公式的值)
3.IF(trueOrfalse,param2,param3)
作用
*对条件进行判断,如果判断为真,如果表达式为true返回值就为param2,如果表达式为false返回值就为param3
IF(表达式,表达式为真时的返回值,表达式为假时的返回值)
4.substring_index(str,delim,count)
- 作用
*切割字符串
substring_index(str,delim,count)
#str 切割对象 要截取的字符串对象
#delim 分隔符 以什么标志去切割目标对象
#num 序号 用来控制切割对象,当为正数(不包括0)时从左向右切割,当为负数时从右向左
5.CAST( target AS CHAR)
作用
*将查询的结果转换成为char类型
CAST(表达式 AS CHAR)
6.CONCAT(char c1, char c2, …, char cn)
- 作用
*进行字符串的拼接
CONCAT(char c1, char c2, …, char cn)
7.DATE_SUB(date,INTERVAL expr type)
- 作用
*函数从日期减去指定的时间间隔
DATE_SUB(date,INTERVAL expr type)
#date:合法的日期表达式
#expr:数量
#type:类型--》MICROSECOND SECOND MINUTE HOUR DAY WEEK MONTH QUARTER YEAR SECOND_MICROSECOND MINUTE_MICROSECOND MINUTE_SECOND HOUR_MICROSECOND HOUR_SECOND HOUR_MINUTE DAY_MICROSECOND DAY_SECOND DAY_MINUTE DAY_HOUR YEAR_MONTH
8.获取datatime类型的年月日
1.直接通过year(),month(),day()
select year(dattime类型的字段),month(dattime类型的字段),day(dattime类型的字段) from '表名'
2.使用datepart关键字获取年月日
datepart('year','字段名'),datepart('month','字段名'),datepart('day','字段名')
9.mysql中保留小数
1.使用round(x,d) -->x为要保留的对象,d是要保留的小数
注意:这种方式保留小数,在位数不够时不会去添0,最后的保留结果会四舍五入,d可以是负数,以小数点为0的分界线,左边的对应的位数以下都变成0
2.turncate(x,d) 和round类似,只是没有四舍五入
3.**format(x,d)**强制保留对应位小数不足填零,返回值为string类型
4.**convert(num,type)**相当于截取
CONVERT(100.3465,DECIMAL(10,2))
边栏推荐
- AutoCAD - layer Linetype
- js setTimeout()与面试题
- Project practice, redis cluster technology learning (10)
- Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
- Postman--使用
- VLAN experiment
- 网络通信学习
- The primary market project galaxy will conduct public offering on coinlist on February 17
- 合并有序数列
- Is this code PHP MySQL redundant?
猜你喜欢
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
pytest--之测试报告allure配置
Stm32 et développement de moteurs (système supérieur)
pytest学习--base
【虚幻4】UMG组件的简介与使用(更新中...)
Redis set password
Pytest learning --base
The primary market project galaxy will conduct public offering on coinlist on February 17
Applet development summary
《MySQL 8 DBA基础教程》简介
随机推荐
Windows环境MySQL8忘记密码文件解决方案
allure--常用配置项
2021-09-12
Redis set password
How much is it to develop a system software in Beijing, and what funds are needed to develop the software
KS009基于SSH实现宠物管理系统
Project practice, redis cluster technology learning (13)
Is this code PHP MySQL redundant?
Pywin32打开指定窗口
【leetcode】33. Search rotation sort array
Pytest-- test report allure configuration
Translation d30 (with AC code POJ 28:sum number)
Commutateur Multi - lentilles Blender
JS reduce accumulator
Metaclass type and using metaclass to implement model class ORM
session-cookie与token
STM32 and motor development (upper system)
Project practice, redis cluster technology learning (VIII)
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer