建库 create database+库名+default+character+set+utf8 删库 drop database+库名 查库 show databases 使用数据库 use+库名 创建表 create table +表名 修改表—添加表 alter table +表名+ add column 删除表 drop table +表名 查看所有表 show tables 查看表结构 desc +表名 插入 insert into+表名+values() 查询表名 Select * from +表名 修改表名 Update +表名 + set +数据类型 删除表名 Delete from +table Lower 数据转小写 Upper 数据转大写 Length 查询数据的长度 Substr 截取(从指定位置截取) Concat 拼接 Replace 替换 Ifunll 如果有null值就可以把这个值换成自己想要换的值 Round & ceil & floor 四舍五入 向上取整 向下取整 UUID() 随机取一位32位的字符串 Now() 北京时间 年 月 日 时 分 秒 Year month day hour minute second 转义字符 'ab'v' 输出报错,因为使用字符varchar多一个‘ 使用转义字符可以消除’的意义 'ab\'v' 去重 distinct 例如:SELECT DISTINCT loc FROM dept; 去除dept表中重复的字段 条件查询 where 模糊查询 like 例如: %a a% %a% 空值 null 使用 is null is not null 区间查询 between and 例如:sal<=3000 and sal>=10000--等效 = sal between 3000 and 10000--等效 分页 limit 写最后面 例如:select * from dept limit 2,3 排序 默认升序 加desc变成降序 order by order by desc 聚合 aggregation 1.count 求总数 select count(*) from emp --慢,只统计非NULL的 2.max 求最大值 3.min 求最小值 4.sum 求和 5.avg 求平均数 分组 group by