当前位置:网站首页>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))
边栏推荐
- SQOOP 1.4.6 INSTALL
- 2021-09-12
- 【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
- 14.信号量的代码实现
- Leetcode -- the nearest common ancestor of 236 binary tree
- Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
- 合并有序数列
- Lunix reallocates root and home space memory
- Centos7 one click compilation and installation of PHP script
- AutoCAD - layer Linetype
猜你喜欢
VLAN experiment
Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
How to judge the quality of primary market projects when the market is depressed?
Pytest framework implements pre post
Blender多鏡頭(多機比特)切換
This article takes you to learn in detail what is fiber to home FTTH
Postman--使用
Brief analysis of edgedb architecture
使用Windbg静态分析dump文件(实战经验总结)
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
随机推荐
Blender多鏡頭(多機比特)切換
Windows环境MySQL8忘记密码文件解决方案
Delivery mode design of Spartacus UI of SAP e-commerce cloud
Sum the two numbers to find the target value
flink 提交程序
AutoCAD - layer Linetype
Project practice, redis cluster technology learning (VIII)
Transport Optimization abstraction
MongoDB-快速上手MongoDB命令行的一些简单操作
02-taildir source
How much is it to develop a system software in Beijing, and what funds are needed to develop the software
虚幻AI蓝图基础笔记(万字整理)
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
01-spooldir
MySQL -- time zone / connector / driver type
Blender volume fog
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
[unity3d] nested use layout group to make scroll view with dynamic sub object height
Blender海洋制作
01安装虚拟机