当前位置:网站首页>MySQL基础-笔记
MySQL基础-笔记
2022-06-23 10:07:00 【cfcoolya】
一.值和列类型
1.数值类型

2.字符串类型

3.日期和时间数值类型

4.null值
- 理解为“没有值”或“未知值”
- 不要用NULL进行算术运算,结果仍为NULL
二.数据字段属性
1.Unsigned
- 无符号
- 声明该数据列不允许负数
2.Zerofill
- 不足位数的用0来填充,如int(3),5则为005
3.Auto_InCrement
- 通常用于设置主键,且为整数类型,自动增长的
- 可定义起始值和步长
- SET @@auto_increment_increment=5,影响所有使用自增的表
4.NULL和NOT NULL
- 默认为NULL,即没有插入该列的数值
- 如果设置NOT NULL,则该列必须有值
三.常用函数
-- 数值函数
abs(x) -- 绝对值 abs(-10.9) = 10
format(x, d) -- 格式化千分位数值 format(1234567.456, 2) = 1,234,567.46
ceil(x) -- 向上取整 ceil(10.1) = 11
floor(x) -- 向下取整 floor (10.1) = 10
round(x) -- 四舍五入去整
mod(m, n) -- m%n m mod n 求余 10%3=1
pi() -- 获得圆周率
pow(m, n) -- m^n
sqrt(x) -- 算术平方根
rand() -- 随机数
truncate(x, d) -- 截取d位小数
-- 时间日期函数
DATE_ADD() -- 给日期添加指定的时间间隔
NOW() -- 2008-12-29 16:25:46
CURDATE() -- 2008-12-29
CURTIME() --16:25:46
current_timestamp(); -- 当前日期时间
date('yyyy-mm-dd hh:ii:ss'); -- 获取日期部分
time('yyyy-mm-dd hh:ii:ss'); -- 获取时间部分
date_format('yyyy-mm-dd hh:ii:ss', '%d %y %a %d %m %b %j'); -- 格式化时间
unix_timestamp(); -- 获得unix时间戳
from_unixtime(); -- 从时间戳获得时间
-- 字符串函数
length(string) -- string长度,字节
char_length(string) -- string的字符个数
substring(str, position [,length]) -- 从str的position开始,取length个字符
replace(str ,search_str ,replace_str) -- 在str中用replace_str替换search_str
instr(string ,substring) -- 返回substring首次在string中出现的位置
concat(string [,...]) -- 连接字串
charset(str) -- 返回字串字符集
lcase(string) -- 转换成小写
left(string, length) -- 从string2中的左边起取length个字符
load_file(file_name) -- 从文件读取内容
locate(substring, string [,start_position]) -- 同instr,但可指定开始位置
lpad(string, length, pad) -- 重复用pad加在string开头,直到字串长度为length
ltrim(string) -- 去除前端空格
repeat(string, count) -- 重复count次
rpad(string, length, pad) --在str后用pad补充,直到长度为length
rtrim(string) -- 去除后端空格
strcmp(string1 ,string2) -- 逐字符比较两字串大小
-- 聚合函数
count()
sum();
max();
min();
avg()--函数返回数值列的平均值。NULL 值不包括在计算中
GROUP BY --结合合计函数,根据一个或多个列对结果集进行分组
HAVING --WHERE 关键字无法与合计函数一起使用
group_concat()
-- 其他常用函数
md5();
default();
四.复杂SQL编写
- https://blog.csdn.net/u010565545/article/details/100785261
- 七种Join理论
边栏推荐
- 数学分析_笔记_第2章:实数与复数
- mysql中innodb下的redo log什么时候开始执行check point落盘的?
- Comic | code review is driving me crazy!
- Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
- Gorm 高级查询
- 2021-04-16数组
- Find minimum in rotated sorted array
- 同花顺是炒股的么?在线开户安全么?
- 一个优秀速开发框架是什么样的?
- 2021-05-07 constructor
猜你喜欢

CVPR大会现场纪念孙剑博士,最佳学生论文授予同济阿里,李飞飞获黄煦涛纪念奖...

个人博客系统毕业设计开题报告

云原生数据库-Amazon RDS

Go unit test

文件IO(1)

Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖

用贪吃蛇小游戏表白(附源码)

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing

Golang 快速上手 (1)

线程池在项目中使用的心得体会
随机推荐
sql编写问题,求出当月和上月的环比值
Form repeated submission problem
2021-05-12接口的定义与实现
2021-05-11 static keyword
Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
sql根据比较日期新建字段
Simple understanding of quick sort
Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
陆奇首次出手投资量子计算
春招面试经验汇总(技术岗)
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
Alimentation des animaux de compagnie basée sur stm32
基于STM32设计的宠物投喂器
Find minimum in rotated sorted array
pycharm安装教程,超详细
2021-05-11抽象类
Nuxt. Differences between JS spa and SSR
RT-Thread 添加 msh 命令
Cloud native database Amazon RDS
Go unit test