当前位置:网站首页>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章:实数与复数
- Personal blog system graduation project opening report
- 开发者,你对云计算可能有些误解
- J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型
- Nuxt. Differences between JS spa and SSR
- NFTs、Web3和元宇宙对数字营销意味着什么?
- 2021-05-12内部类
- Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
- 一个优秀速开发框架是什么样的?
- Build a security video monitoring platform using Huawei cloud ECS server
猜你喜欢

Bugs encountered in Oracle

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

IPv6 的速度比 IPv4 更快?

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

laravel8 beanstalk 使用说明

Lu Qi invests in quantum computing for the first time

Build a security video monitoring platform using Huawei cloud ECS server

Build the information and innovation industry ecology, and make mobile cloud based on the whole stack of independent innovation

Go unit test

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
随机推荐
在OpenCloudOS使用snap安装.NET 6
Developer, you may have some misunderstandings about cloud computing
Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
NiO example
2021-05-11 abstract class
Cloud native database Amazon RDS
RPC kernel details you must know (worth collecting)!!!
2021-05-10 method rewrite polymorphism considerations
Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
Golang 快速上手 (1)
[day 23] given an array of length N, insert element x into the position specified by the array | array insertion operation 4
Go string comparison
STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
构建信创产业生态,移动云立足全栈自主创新连放大招
2021-05-07构造器
实现领域驱动设计 - 使用ABP框架 - 通用准则
Navagation navigation
Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
Personal blog system graduation project opening report
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