##### 增删改查
增 : insert into 表名(字段名,...) value (值,.....)
删: delete from 表名 where 条件 (删除记录)
delete from 表名 (删除所有记录)
drop 表名 (删除表)
改: update 表名 set 字段=值 where 条件 (有条件则修改符合条件的 无则是全部)
查: select * from 表名 (显示所有字段)
select * from 表名 where 条件
关系运算符:= != > < <= >=
select * from 表名 where 字段名 (not)in (元素,...) (不在 或 在)
select * from 表名 where 字段名 (not)between 值1 and 值2(不在...里 或 在...里)
select * from 表名 where 字段名 is(not) null (是否为空)
select distinct 字段名 from 表名 (去重)
select * from 表名 where 字段名 (not)like '匹配字符串' (关键字查询)
select * from 表名 where like '%a%' (模糊查询 包含a的)
select * from 表名 where 条件1 and 条件2 ...... (多条件精准查询)
select * from 表名 where 条件1 or 条件2 (或查询)
##### 高级查询
##### 聚合函数
*count()记录总条数*
select count(*) from 表名
*sum()所有值的总和*
select sum(字段名) from 表名
*AVG()平均值*
select AVG(字段名) from 表名
*max()最大值*
select max(字段名) from 表名
*min()最小值*
select min(字段名) from 表名
##### 排序
select 字段,... from 表名 order by 字段 asc (升序)
select 字段,... from 表名 order by 字段 desc (降序)
##### 分组
select 字段,.. from 表名 group by 字段,...
select sum(字段名) from 表名 group by 字段名 having sum(字段名) < 10 (查询某字段总和小于10的)
##### 分页
select * from 表名 limit 0,2 (每页显示2个,第一个页面)
##### 连接查询
inner join ... on 等值连接
left join ... on 左连接
right join ... on 右连接
select 表A.字段1,表B.字段1 from 表A [inner | left | right] join 表B on 表A.字段2 = 表B.字段2
##### 子查询
select * from 表A where 字段1 > (select AVG(字段) from 表B)
##### 约束
int unsigned 无符号整形
auto_increment 表示自动增长
not null 表示不能为空
primary key 表示主键
default 默认值
##### 外键
建表时: foreign key(a_id) references 表B(id)
取消外键约束: show create table 表名 (获取名称之后 根据名称删除)
添加外键约束: alter table 要连接表名 add foreign key (a_id) references 被连接的表名(id)